Skip to content

Commit

Permalink
Added test for server operation mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
bsneed committed Nov 16, 2023
1 parent 85eea48 commit 3ab0792
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Tests/Segment-Tests/Analytics_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -644,4 +644,38 @@ final class Analytics_Tests: XCTestCase {
XCTAssertTrue(shared2 === shared)

}

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

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
}

// completion shouldn't be called before flush returned.
XCTAssertTrue(completionCalled)
XCTAssertEqual(analytics.pendingUploads!.count, 0)

// put another event in the pipe.
analytics.track(name: "completion test2")
analytics.flush()

// flush shouldn't return until all uploads are done, cuz
// it's running in sync mode.
XCTAssertEqual(analytics.pendingUploads!.count, 0)
}
}

0 comments on commit 3ab0792

Please sign in to comment.