Skip to content

Commit

Permalink
Respond to review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mscwilson committed Sep 29, 2023
1 parent 8dac529 commit 205d7ae
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
10 changes: 5 additions & 5 deletions Sources/Core/Tracker/Tracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class Tracker: NSObject {
return _deepLinkContext
}
set(deepLinkContext) {
serialQueue.async {
serialQueue.sync {
self._deepLinkContext = deepLinkContext
if deepLinkContext {
self.addOrReplace(stateMachine: DeepLinkStateMachine())
Expand All @@ -191,7 +191,7 @@ class Tracker: NSObject {
return _screenContext
}
set(screenContext) {
serialQueue.async {
serialQueue.sync {
self._screenContext = screenContext
if screenContext {
self.addOrReplace(stateMachine: ScreenStateMachine())
Expand Down Expand Up @@ -240,7 +240,7 @@ class Tracker: NSObject {
return _lifecycleEvents
}
set(lifecycleEvents) {
serialQueue.async {
serialQueue.sync {
self._lifecycleEvents = lifecycleEvents
if lifecycleEvents {
self.addOrReplace(stateMachine: LifecycleStateMachine())
Expand Down Expand Up @@ -461,9 +461,9 @@ class Tracker: NSObject {
if let payload = self.payload(with: trackerEvent) {
emitter.addPayload(toBuffer: payload)
stateManager.afterTrack(event: trackerEvent)
return
} else {
logDebug(message: "Event not tracked due to filtering")
}
logDebug(message: "Event not tracked due to filtering")
}

func payload(with event: TrackerEvent) -> Payload? {
Expand Down
4 changes: 4 additions & 0 deletions Sources/Core/Utils/DispatchQueueWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class DispatchQueueWrapper: DispatchQueueWrapperProtocol {
queue = DispatchQueue(label: label)
}

func sync(_ callback: @escaping () -> Void) {
queue.sync(execute: callback)
}

func async(_ callback: @escaping () -> Void) {
queue.async(execute: callback)
}
Expand Down
1 change: 1 addition & 0 deletions Sources/Core/Utils/DispatchQueueWrapperProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
import Foundation

protocol DispatchQueueWrapperProtocol: AnyObject {
func sync(_ callback: @escaping () -> Void)
func async(_ callback: @escaping () -> Void)
}
4 changes: 2 additions & 2 deletions Tests/Configurations/TestTrackerConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ class TestTrackerConfiguration: XCTestCase {
let tracker = Snowplow.createTracker(namespace: "namespace", network: networkConfig, configurations: [trackerConfig, sessionConfig])

_ = tracker?.track(Timing(category: "cat", variable: "var", timing: 123))
Thread.sleep(forTimeInterval: 3)
Thread.sleep(forTimeInterval: 0.1)
tracker?.session?.startNewSession()
_ = tracker?.track(Timing(category: "cat", variable: "var", timing: 123))
Thread.sleep(forTimeInterval: 3)
Thread.sleep(forTimeInterval: 0.1)

wait(for: [expectation], timeout: 10)
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/Configurations/TestTrackerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ class TestTrackerController: XCTestCase {
tracker?.emitter?.pause()

_ = tracker?.track(Structured(category: "c", action: "a"))
Thread.sleep(forTimeInterval: 3)
Thread.sleep(forTimeInterval: 0.1)
let sessionIdBefore = tracker?.session?.sessionId

tracker?.userAnonymisation = true
_ = tracker?.track(Structured(category: "c", action: "a"))
Thread.sleep(forTimeInterval: 3)
Thread.sleep(forTimeInterval: 0.1)
let sessionIdAnonymous = tracker?.session?.sessionId

XCTAssertFalse((sessionIdBefore == sessionIdAnonymous))

tracker?.userAnonymisation = false
_ = tracker?.track(Structured(category: "c", action: "a"))
Thread.sleep(forTimeInterval: 3)
Thread.sleep(forTimeInterval: 0.1)
let sessionIdNotAnonymous = tracker?.session?.sessionId

XCTAssertFalse((sessionIdAnonymous == sessionIdNotAnonymous))
Expand Down
4 changes: 4 additions & 0 deletions Tests/Utils/MockDispatchQueueWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class MockDispatchQueueWrapper: DispatchQueueWrapperProtocol {
queue = DispatchQueue(label: label)
}

func sync(_ callback: @escaping () -> Void) {
queue.sync(execute: callback)
}

func async(_ callback: @escaping () -> Void) {
// execute synchronously!
queue.sync(execute: callback)
Expand Down

0 comments on commit 205d7ae

Please sign in to comment.