From 77f02fc706e9a8bd8da9ef5323c2aae4187080bc Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Tue, 8 Oct 2024 15:26:02 -0700 Subject: [PATCH] Yield `TimeoutError` before cancelling body task in `withTimeout` Otherwise, the body task might finish before we yield the `TimeoutError` and thus `withTimeout` would not actually throw a `TimeoutError`. rdar://137171114 --- Sources/SKTestSupport/RepeatUntilExpectedResult.swift | 1 - Sources/SwiftExtensions/AsyncUtils.swift | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Sources/SKTestSupport/RepeatUntilExpectedResult.swift b/Sources/SKTestSupport/RepeatUntilExpectedResult.swift index 2571b4eb..1bb8f40a 100644 --- a/Sources/SKTestSupport/RepeatUntilExpectedResult.swift +++ b/Sources/SKTestSupport/RepeatUntilExpectedResult.swift @@ -26,7 +26,6 @@ package func repeatUntilExpectedResult( file: StaticString = #filePath, line: UInt = #line ) async throws { - logger.info("x: \(Int(timeout.seconds / sleepInterval.seconds))") for _ in 0..( let timeoutTask = Task { try await Task.sleep(for: duration) - bodyTask.cancel() continuation.yield(with: .failure(TimeoutError())) + bodyTask.cancel() } mutableTasks = [bodyTask, timeoutTask] }