Skip to content

[Concurrency] Harden task group test which is sensitive to timing #75612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions test/Concurrency/Runtime/async_taskgroup_throw_rethrow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,15 @@ func test_discardingTaskGroup_automaticallyRethrows_first_withThrowingBodyFirst(
_ = await echo(1)
}
group.addTask {
try? await Task.sleep(until: .now + .seconds(10), clock: .continuous)
let error = Boom(id: "task, second, isCancelled:\(Task.isCancelled)")
let start: ContinuousClock.Instant = .now
do {
// Sleep for a long time because we need to account for very slow test runners;
// This should rarely actually wait so long as throwing from the group will cancel and wake-up this child task.
try await Task.sleep(until: start + .seconds(30), clock: .continuous)
} catch {
print("Child task cancelled! Slept: \(ContinuousClock.Instant.now - start)")
}
let error = Boom(id: "task, second, isCancelled:\(Task.isCancelled), slept: \(ContinuousClock.Instant.now - start)")
print("Throwing: \(error)")
throw error
}
Expand All @@ -173,6 +180,7 @@ func test_discardingTaskGroup_automaticallyRethrows_first_withThrowingBodyFirst(
fatalError("Expected error to be thrown")
} catch {
// CHECK: Throwing: Boom(id: "body, first, isCancelled:false
// CHECK: Child task cancelled!
// CHECK: Throwing: Boom(id: "task, second, isCancelled:true
// and only then the re-throw happens:
// CHECK: rethrown: Boom(id: "body, first
Expand Down