Skip to content

Dial back a racy race test for Task.sleep(nanoseconds:). #38363

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
Jul 13, 2021
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: 2 additions & 10 deletions test/Concurrency/Runtime/async_task_sleep_cancel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ import Dispatch
static func testSleepCancelledBeforeStarted() async {
// CHECK-NEXT: Testing sleep that gets cancelled before it starts
print("Testing sleep that gets cancelled before it starts")
let start = DispatchTime.now()

let sleepyTask = Task {
try await Task.sleep(nanoseconds: UInt64(pause))
}
Expand All @@ -65,20 +63,14 @@ import Dispatch
sleepyTask.cancel()
try await sleepyTask.value

fatalError("sleep(nanoseconds:) should have thrown CancellationError")
print("Bah, weird scheduling")
} catch is CancellationError {
// CHECK-NEXT: Caught the cancellation error
print("Caught the cancellation error")

let stop = DispatchTime.now()

// assert that we stopped early.
assert(stop < (start + .nanoseconds(pause)))
} catch {
fatalError("sleep(nanoseconds:) threw some other error: \(error)")
}

// CHECK-NEXT: Cancelled!
// CHECK: Cancelled!
print("Cancelled!")
}

Expand Down