33// REQUIRES: executable_test
44// REQUIRES: concurrency
55
6- // rdar://76038845
76// REQUIRES: concurrency_runtime
87// UNSUPPORTED: back_deployment_runtime
98
10- import Dispatch
11-
129@available ( SwiftStdlib 6 . 0 , * )
1310func test_withTaskGroup_addUnlessCancelled( ) async throws {
1411 let task = Task {
1512 await withTaskGroup ( of: Void . self) { group in
1613 print ( " Inner: Sleep... " )
17- try ? await Task . sleep ( nanoseconds : 2_000_000_000 )
14+ try ? await Task . sleep ( for : . seconds ( 60 ) ) // we'll never actually wait 10 seconds, as this will be woken up by cancel
1815 print ( " Inner: Task.isCancelled: \( Task . isCancelled) " )
1916
2017 let added = group. addTaskUnlessCancelled {
2118 print ( " Added Task! Child Task.isCancelled: \( Task . isCancelled) " )
2219 }
23- print ( " Inner: Task added = \( added) " ) // CHECK: Task added = false
20+ print ( " Inner: Task added = \( added) " ) // CHECK: Inner: Task added = false
2421 }
2522 }
2623
27- try ? await Task . sleep ( nanoseconds: 1_000_000 )
2824 print ( " Outer: Cancel! " )
2925 task. cancel ( )
3026 print ( " Outer: Cancelled " )
@@ -37,17 +33,16 @@ func test_withDiscardingTaskGroup_addUnlessCancelled() async throws {
3733 let task = Task {
3834 await withDiscardingTaskGroup { group in
3935 print ( " Inner: Sleep... " )
40- try ? await Task . sleep ( nanoseconds : 2_000_000_000 )
36+ try ? await Task . sleep ( for : . seconds ( 60 ) ) // we'll never actually wait 10 seconds, as this will be woken up by cancel
4137 print ( " Inner: Task.isCancelled: \( Task . isCancelled) " )
4238
4339 let added = group. addTaskUnlessCancelled {
4440 print ( " Added Task! Child Task.isCancelled: \( Task . isCancelled) " )
4541 }
46- print ( " Inner: Task added = \( added) " ) // CHECK: Task added = false
42+ print ( " Inner: Task added = \( added) " ) // CHECK: Inner: Task added = false
4743 }
4844 }
4945
50- try ? await Task . sleep ( nanoseconds: 1_000_000 )
5146 print ( " Outer: Cancel! " )
5247 task. cancel ( )
5348 print ( " Outer: Cancelled " )
0 commit comments