From 52aa1f703f13fb0ae0c797676fd796a44e254a64 Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Wed, 13 Aug 2025 09:40:02 +0200 Subject: [PATCH] test: Use XCTestExpectation for FlushTests Replace DispatchGroup with XCTextExpectation in SentryHttpTransportFlushIntegrationTests. --- ...ryHttpTransportFlushIntegrationTests.swift | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/Tests/SentryTests/Networking/SentryHttpTransportFlushIntegrationTests.swift b/Tests/SentryTests/Networking/SentryHttpTransportFlushIntegrationTests.swift index 4de4af09631..a9f26fc5e50 100644 --- a/Tests/SentryTests/Networking/SentryHttpTransportFlushIntegrationTests.swift +++ b/Tests/SentryTests/Networking/SentryHttpTransportFlushIntegrationTests.swift @@ -98,48 +98,58 @@ final class SentryHttpTransportFlushIntegrationTests: XCTestCase { for _ in 0..<30 { sut.send(envelope: SentryEnvelope(event: Event())) } - // Wait until the dispath queue drains to confirm the envelope is stored + // Wait until the dispatch queue drains to confirm the envelope is stored waitForEnvelopeToBeStored(dispatchQueueWrapper) requestManager.returnResponse(response: HTTPURLResponse()) - let initialFlushCallGroup = DispatchGroup() - let ensureFlushingGroup = DispatchGroup() + let initialFlushCallExpectation = XCTestExpectation(description: "Initial flush call should succeed") + initialFlushCallExpectation.assertForOverFulfill = true + + let ensureFlushingExpectation = XCTestExpectation(description: "Ensure flushing is called") + ensureFlushingExpectation.assertForOverFulfill = true + let ensureFlushingQueue = DispatchQueue(label: "First flushing") sut.setStartFlushCallback { - ensureFlushingGroup.leave() + ensureFlushingExpectation.fulfill() } - initialFlushCallGroup.enter() - ensureFlushingGroup.enter() ensureFlushingQueue.async { XCTAssertEqual(.success, sut.flush(flushTimeout), "Initial call to flush should succeed") - initialFlushCallGroup.leave() + initialFlushCallExpectation.fulfill() } // Ensure transport is flushing. - ensureFlushingGroup.waitWithTimeout() + wait(for: [ensureFlushingExpectation], timeout: 10.0) // Now the transport should also have left the synchronized block, and the // flush should return immediately. - let parallelFlushCallsGroup = DispatchGroup() + let loopCount = 2 + let parallelFlushCallsExpectation = XCTestExpectation(description: "Parallel flush calls should return immediately") + parallelFlushCallsExpectation.expectedFulfillmentCount = loopCount + parallelFlushCallsExpectation.assertForOverFulfill = true + let initiallyInactiveQueue = DispatchQueue(label: "testFlush_CalledMultipleTimes_ImmediatelyReturnsFalse", qos: .userInitiated, attributes: [.concurrent, .initiallyInactive]) - for _ in 0..<2 { - parallelFlushCallsGroup.enter() + for _ in 0..