From f14fe5d2059b0bffbc46333dba50089a6900d560 Mon Sep 17 00:00:00 2001 From: Chris Leonavicius Date: Fri, 22 Mar 2024 11:43:26 -0700 Subject: [PATCH] test: fix failures on watchOS (#144) --- .../Utilities/EventPipelineTests.swift | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Tests/AmplitudeTests/Utilities/EventPipelineTests.swift b/Tests/AmplitudeTests/Utilities/EventPipelineTests.swift index e96ba747..06fa82f5 100644 --- a/Tests/AmplitudeTests/Utilities/EventPipelineTests.swift +++ b/Tests/AmplitudeTests/Utilities/EventPipelineTests.swift @@ -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() { @@ -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) @@ -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 { @@ -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)