Skip to content

Commit 3ab0792

Browse files
committed
Added test for server operation mode.
1 parent 85eea48 commit 3ab0792

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Tests/Segment-Tests/Analytics_Tests.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,4 +644,38 @@ final class Analytics_Tests: XCTestCase {
644644
XCTAssertTrue(shared2 === shared)
645645

646646
}
647+
648+
func testServerOperatingMode() {
649+
// Use a specific writekey to this test so we do not collide with other cached items.
650+
let analytics = Analytics(configuration: Configuration(writeKey: "testFlush_serverMode")
651+
.flushInterval(9999)
652+
.flushAt(9999)
653+
.operatingMode(.server))
654+
655+
waitUntilStarted(analytics: analytics)
656+
657+
analytics.storage.hardReset(doYouKnowHowToUseThis: true)
658+
659+
@Atomic var completionCalled = false
660+
661+
// put an event in the pipe ...
662+
analytics.track(name: "completion test1")
663+
// flush it, that'll get us an upload going
664+
analytics.flush {
665+
// verify completion is called.
666+
completionCalled = true
667+
}
668+
669+
// completion shouldn't be called before flush returned.
670+
XCTAssertTrue(completionCalled)
671+
XCTAssertEqual(analytics.pendingUploads!.count, 0)
672+
673+
// put another event in the pipe.
674+
analytics.track(name: "completion test2")
675+
analytics.flush()
676+
677+
// flush shouldn't return until all uploads are done, cuz
678+
// it's running in sync mode.
679+
XCTAssertEqual(analytics.pendingUploads!.count, 0)
680+
}
647681
}

0 commit comments

Comments
 (0)