diff --git a/Tests/SentryTests/TestUtils/Async.swift b/Tests/SentryTests/TestUtils/Async.swift index 5bc03e78e80..3141317917c 100644 --- a/Tests/SentryTests/TestUtils/Async.swift +++ b/Tests/SentryTests/TestUtils/Async.swift @@ -1,18 +1,6 @@ import Foundation import XCTest -func delayNonBlocking(timeout: Double = 0.2) { - let group = DispatchGroup() - group.enter() - let queue = DispatchQueue(label: "delay") - - queue.asyncAfter(deadline: .now() + timeout) { - group.leave() - } - - group.wait() -} - extension DispatchGroup { /** diff --git a/Tests/SentryTests/TestUtils/TestExtensions.swift b/Tests/SentryTests/TestUtils/TestExtensions.swift index 8be0dd39823..52f3843c849 100644 --- a/Tests/SentryTests/TestUtils/TestExtensions.swift +++ b/Tests/SentryTests/TestUtils/TestExtensions.swift @@ -7,3 +7,20 @@ extension XCTest { return try Data(contentsOf: URL(fileURLWithPath: path ?? "")) } } + +extension XCTestCase { + + func delayNonBlocking(timeout: Double = 0.2) { + let expectation = XCTestExpectation(description: "Finish Delay") + expectation.assertForOverFulfill = true + + let queue = DispatchQueue(label: "delay") + + queue.asyncAfter(deadline: .now() + timeout) { + expectation.fulfill() + } + + let timeoutWithBuffer = timeout * 1.3 + self.wait(for: [expectation], timeout: timeoutWithBuffer) + } +}