@@ -49,10 +49,12 @@ struct CancellableQueueTests {
4949 func cancelTasks_fifoQueue_cancelsCurrentlyExecutingTask( ) async {
5050 let systemUnderTest = CancellableQueue ( underlyingQueue: FIFOQueue ( ) )
5151 let taskStarted = Semaphore ( )
52+ let taskAllowedToEnd = Semaphore ( )
5253
5354 // Create a task that signals when it starts, then waits
5455 let task = Task ( on: systemUnderTest) {
5556 await taskStarted. signal ( )
57+ await taskAllowedToEnd. wait ( )
5658 }
5759
5860 // Wait for the task to start executing
@@ -61,18 +63,23 @@ struct CancellableQueueTests {
6163 // Cancel all tasks
6264 systemUnderTest. cancelTasks ( )
6365
66+ // Allow the task to end now that we've cancelled it.
67+ await taskAllowedToEnd. signal ( )
68+
6469 #expect( task. isCancelled)
6570 }
6671
6772 @Test
6873 func cancelTasks_fifoQueue_cancelsCurrentlyExecutingAndPendingTasks( ) async {
6974 let systemUnderTest = CancellableQueue ( underlyingQueue: FIFOQueue ( ) )
7075 let taskStarted = Semaphore ( )
76+ let taskAllowedToEnd = Semaphore ( )
7177 let counter = Counter ( )
7278
7379 // Create a task that signals when it starts
7480 let task1 = Task ( on: systemUnderTest, isolatedTo: counter) { _ in
7581 await taskStarted. signal ( )
82+ await taskAllowedToEnd. wait ( )
7683 }
7784
7885 // Create pending tasks that won't start until the first task completes
@@ -86,6 +93,9 @@ struct CancellableQueueTests {
8693 // Cancel all tasks
8794 systemUnderTest. cancelTasks ( )
8895
96+ // Allow the task to end now that we've cancelled it.
97+ await taskAllowedToEnd. signal ( )
98+
8999 #expect( task1. isCancelled)
90100 #expect( task2. isCancelled)
91101 #expect( task3. isCancelled)
0 commit comments