Skip to content

Commit

Permalink
test: fix failures on watchOS (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
crleona authored Mar 22, 2024
1 parent a6f1559 commit f14fe5d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Tests/AmplitudeTests/Utilities/EventPipelineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ final class EventPipelineTests: XCTestCase {
configuration = Configuration(
apiKey: "testApiKey",
flushIntervalMillis: Int(Self.FLUSH_INTERVAL_SECONDS * 1000),
storageProvider: storage
storageProvider: storage,
offline: NetworkConnectivityCheckerPlugin.Disabled
)
let amplitude = Amplitude(configuration: configuration)
httpClient = FakeHttpClient(configuration: configuration, diagnostics: configuration.diagonostics)
pipeline = EventPipeline(amplitude: amplitude)
pipeline.httpClient = httpClient
pipeline.flushTimer?.suspend()

}

override func tearDown() {
Expand Down Expand Up @@ -74,6 +77,8 @@ final class EventPipelineTests: XCTestCase {
}

func testFlushWhenOffline() {
pipeline.amplitude.configuration.offline = false

let testEvent = BaseEvent(userId: "unit-test", deviceId: "unit-test-machine", eventType: "testEvent")
try? pipeline.storage?.write(key: StorageKey.EVENTS, value: testEvent)

Expand All @@ -91,6 +96,9 @@ final class EventPipelineTests: XCTestCase {
let testEvent = BaseEvent(userId: "unit-test", deviceId: "unit-test-machine", eventType: "testEvent")
try? pipeline.storage?.write(key: StorageKey.EVENTS, value: testEvent)

let httpResponseExpectation = expectation(description: "httpresponse")
httpClient.uploadExpectations = [httpResponseExpectation]

let flushExpectations = (0..<2).map { _ in
let expectation = expectation(description: "flush")
pipeline.flush {
Expand All @@ -99,8 +107,9 @@ final class EventPipelineTests: XCTestCase {
return expectation
}

let waitResult = XCTWaiter.wait(for: flushExpectations, timeout: 1)
XCTAssertNotEqual(waitResult, .timedOut)
wait(for: flushExpectations, timeout: 1)
wait(for: [httpResponseExpectation], timeout: 1)

XCTAssertEqual(httpClient.uploadCount, 1)
let uploadedEvents = BaseEvent.fromArrayString(jsonString: httpClient.uploadedEvents[0])
XCTAssertEqual(uploadedEvents?.count, 1)
Expand Down

0 comments on commit f14fe5d

Please sign in to comment.