Skip to content

Commit

Permalink
fix: improve reliability of flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
crleona committed Mar 20, 2024
1 parent 8eedaab commit 9ad143b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Tests/AmplitudeTests/Utilities/EventPipelineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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 = [
Expand All @@ -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)

Expand Down

0 comments on commit 9ad143b

Please sign in to comment.