Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bsneed committed Nov 17, 2023
1 parent ffaaf03 commit 2f61ef7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
5 changes: 3 additions & 2 deletions Sources/Segment/Analytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,9 @@ extension Analytics {
if operatingMode == .synchronous {
flushGroup.wait()
// we need to call completion on our own since
// we skipped setting up notify.
if let completion { DispatchQueue.main.async { completion() }}
// we skipped setting up notify. we don't need to do it on
// .main since we are in synchronous mode.
if let completion { completion() }
}
}

Expand Down
33 changes: 31 additions & 2 deletions Tests/Segment-Tests/Analytics_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -692,9 +692,38 @@ final class Analytics_Tests: XCTestCase {

}

func testServerOperatingMode() {
func testAsyncOperatingMode() {
// Use a specific writekey to this test so we do not collide with other cached items.
let analytics = Analytics(configuration: Configuration(writeKey: "testFlush_serverMode")
let analytics = Analytics(configuration: Configuration(writeKey: "testFlush_asyncMode")
.flushInterval(9999)
.flushAt(9999)
.operatingMode(.asynchronous))

waitUntilStarted(analytics: analytics)

analytics.storage.hardReset(doYouKnowHowToUseThis: true)

@Atomic var completionCalled = false

// put an event in the pipe ...
analytics.track(name: "completion test1")
// flush it, that'll get us an upload going
analytics.flush {
// verify completion is called.
completionCalled = true
}

while !completionCalled {
RunLoop.main.run(until: Date.distantPast)
}

XCTAssertTrue(completionCalled)
XCTAssertEqual(analytics.pendingUploads!.count, 0)
}

func testSyncOperatingMode() {
// Use a specific writekey to this test so we do not collide with other cached items.
let analytics = Analytics(configuration: Configuration(writeKey: "testFlush_syncMode")
.flushInterval(9999)
.flushAt(9999)
.operatingMode(.synchronous))
Expand Down

0 comments on commit 2f61ef7

Please sign in to comment.