Skip to content

Commit a596a03

Browse files
committed
Add a test for Task.sleep(nanoseconds: 0).
1 parent 4a0723f commit a596a03

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

test/Concurrency/Runtime/async_task_sleep_cancel.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Dispatch
1919
// CHECK: Starting!
2020
print("Starting!")
2121
await testSleepFinished()
22+
await testSleepMomentary()
2223
await testSleepCancelledBeforeStarted()
2324
await testSleepCancelled()
2425
}
@@ -40,6 +41,17 @@ import Dispatch
4041
print("Wakey wakey!")
4142
}
4243

44+
static func testSleepMomentary() async {
45+
// CHECK-NEXT: Testing sleep that completes instantly
46+
print("Testing sleep that completes instantly")
47+
48+
// try! will fail if the task got cancelled (which shouldn't happen).
49+
try! await Task.sleep(nanoseconds: 0)
50+
51+
// CHECK-NEXT: Wakey wakey!
52+
print("Wakey wakey!")
53+
}
54+
4355
static func testSleepCancelledBeforeStarted() async {
4456
// CHECK-NEXT: Testing sleep that gets cancelled before it starts
4557
print("Testing sleep that gets cancelled before it starts")

0 commit comments

Comments
 (0)