From 9ad143bd0e95612a0dcd0583ac532adad32ad037 Mon Sep 17 00:00:00 2001 From: Chris Leonavicius Date: Wed, 20 Mar 2024 15:16:29 -0700 Subject: [PATCH] fix: improve reliability of flaky test --- .../Utilities/EventPipelineTests.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/AmplitudeTests/Utilities/EventPipelineTests.swift b/Tests/AmplitudeTests/Utilities/EventPipelineTests.swift index 8a95a0bf..cb32e111 100644 --- a/Tests/AmplitudeTests/Utilities/EventPipelineTests.swift +++ b/Tests/AmplitudeTests/Utilities/EventPipelineTests.swift @@ -10,7 +10,7 @@ import XCTest @testable import AmplitudeSwift final class EventPipelineTests: XCTestCase { - private static let FLUSH_INTERVAL_SECONDS = 1.0 + private static let FLUSH_INTERVAL_SECONDS = 300.0 private var configuration: Configuration! private var pipeline: EventPipeline! @@ -108,11 +108,6 @@ final class EventPipelineTests: XCTestCase { } func testInvalidEventUpload() { - (0..<2).forEach { i in - let testEvent = BaseEvent(userId: "test", deviceId: "test-machine", eventType: "testEvent-\(i)") - try? pipeline.storage?.write(key: StorageKey.EVENTS, value: testEvent) - } - let invalidResponseData = "{\"events_with_invalid_fields\": {\"user_id\": [0]}}".data(using: .utf8)! httpClient.uploadResults = [ @@ -122,6 +117,11 @@ final class EventPipelineTests: XCTestCase { let uploadExpectations = (0..<2).map { _ in expectation(description: "httpresponse") } httpClient.uploadExpectations = uploadExpectations + (0..<2).forEach { i in + let testEvent = BaseEvent(userId: "test", deviceId: "test-machine", eventType: "testEvent-\(i)") + try? pipeline.storage?.write(key: StorageKey.EVENTS, value: testEvent) + } + pipeline.flush() wait(for: [uploadExpectations[0]], timeout: 1)