From ec2a96ec5d59a5e1b3bfee1ed29f30fc4e121aff Mon Sep 17 00:00:00 2001 From: Michael Grosse Huelsewiesche Date: Sun, 24 Nov 2024 20:17:36 -0500 Subject: [PATCH] Adding test that reproduced crash before fix --- Tests/Segment-Tests/Telemetry_Tests.swift | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Tests/Segment-Tests/Telemetry_Tests.swift b/Tests/Segment-Tests/Telemetry_Tests.swift index 9097fbd..ed0cc0e 100644 --- a/Tests/Segment-Tests/Telemetry_Tests.swift +++ b/Tests/Segment-Tests/Telemetry_Tests.swift @@ -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..