Skip to content

Commit

Permalink
Adding test that reproduced crash before fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelGHSeg committed Nov 25, 2024
1 parent f8a29a3 commit ec2a96e
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Tests/Segment-Tests/Telemetry_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,39 @@ class TelemetryTests: XCTestCase {
Telemetry.shared.error(metric: Telemetry.INVOKE_ERROR_METRIC, log: longString) { $0["writekey"] = longString }
XCTAssertTrue(Telemetry.shared.queue.count < 1000)
}

func testConcurrentErrorReporting() {
Telemetry.shared.enable = true
Telemetry.shared.start()
let operationCount = 200

var concurrentExpectation = XCTestExpectation(description: "High pressure operations")
concurrentExpectation.expectedFulfillmentCount = operationCount

// Use multiple dispatch queues to increase concurrency
let queues = [
DispatchQueue.global(qos: .userInitiated),
DispatchQueue.global(qos: .default),
DispatchQueue.global(qos: .utility)
]
for i in 0..<operationCount {
// Round-robin between different queues
let queue = queues[i % queues.count]
queue.async {
Telemetry.shared.error(
metric: Telemetry.INVOKE_ERROR_METRIC,
log: "High pressure test \(i)"
) { tags in
tags["error"] = "pressure_test_key"
tags["queue"] = "\(i % queues.count)"
tags["iteration"] = "\(i)"
}
concurrentExpectation.fulfill()
}
}
wait(for: [concurrentExpectation], timeout: 15.0)
XCTAssertTrue(Telemetry.shared.queue.count == Telemetry.shared.maxQueueSize)
}
}

// Mock URLSession
Expand Down

0 comments on commit ec2a96e

Please sign in to comment.