@@ -9,14 +9,18 @@ class CancellationSourceTests: XCTestCase {
9
9
let task = Task { try await Task . sleep ( seconds: 10 ) }
10
10
source. register ( task: task)
11
11
source. cancel ( )
12
- try await waitUntil ( task, timeout: 5 ) { $0. isCancelled }
12
+ try await source. wait ( forSeconds: 5 )
13
+ XCTAssertTrue ( source. isCancelled)
14
+ XCTAssertTrue ( task. isCancelled)
13
15
}
14
16
15
17
func testTaskCancellationWithTimeout( ) async throws {
16
18
let task = Task { try await Task . sleep ( seconds: 10 ) }
17
19
let source = CancellationSource ( cancelAfterNanoseconds: UInt64 ( 1E9 ) )
18
20
source. register ( task: task)
19
- try await waitUntil ( task, timeout: 5 ) { $0. isCancelled }
21
+ try await source. wait ( forSeconds: 5 )
22
+ XCTAssertTrue ( source. isCancelled)
23
+ XCTAssertTrue ( task. isCancelled)
20
24
}
21
25
22
26
#if swift(>=5.7)
@@ -33,7 +37,9 @@ class CancellationSourceTests: XCTestCase {
33
37
)
34
38
let task = Task { try await Task . sleep ( seconds: 10 , clock: clock) }
35
39
source. register ( task: task)
36
- try await waitUntil ( task, timeout: 5 ) { $0. isCancelled }
40
+ try await source. wait ( forSeconds: 5 , clock: clock)
41
+ XCTAssertTrue ( source. isCancelled)
42
+ XCTAssertTrue ( task. isCancelled)
37
43
}
38
44
#endif
39
45
@@ -43,7 +49,9 @@ class CancellationSourceTests: XCTestCase {
43
49
let task = Task { try await Task . sleep ( seconds: 10 ) }
44
50
source. register ( task: task)
45
51
pSource. cancel ( )
46
- try await waitUntil ( task, timeout: 5 ) { $0. isCancelled }
52
+ try await source. wait ( forSeconds: 5 )
53
+ XCTAssertTrue ( source. isCancelled)
54
+ XCTAssertTrue ( task. isCancelled)
47
55
}
48
56
49
57
func testTaskCancellationWithMultipleLinkedSources( ) async throws {
@@ -53,7 +61,9 @@ class CancellationSourceTests: XCTestCase {
53
61
let task = Task { try await Task . sleep ( seconds: 10 ) }
54
62
source. register ( task: task)
55
63
pSource1. cancel ( )
56
- try await waitUntil ( task, timeout: 5 ) { $0. isCancelled }
64
+ try await source. wait ( forSeconds: 5 )
65
+ XCTAssertTrue ( source. isCancelled)
66
+ XCTAssertTrue ( task. isCancelled)
57
67
}
58
68
59
69
func testAlreadyCancelledTask( ) async throws {
@@ -76,7 +86,9 @@ class CancellationSourceTests: XCTestCase {
76
86
source. register ( task: task)
77
87
try await task. value
78
88
source. cancel ( )
79
- XCTAssertFalse ( task. isCancelled)
89
+ try await source. wait ( forSeconds: 5 )
90
+ XCTAssertTrue ( source. isCancelled)
91
+ try await task. value
80
92
}
81
93
82
94
func testConcurrentCancellation( ) async throws {
@@ -87,15 +99,19 @@ class CancellationSourceTests: XCTestCase {
87
99
for _ in 0 ..< 10 { group. addTask { source. cancel ( ) } }
88
100
await group. waitForAll ( )
89
101
}
90
- try await waitUntil ( task, timeout: 5 ) { $0. isCancelled }
102
+ try await source. wait ( forSeconds: 5 )
103
+ XCTAssertTrue ( source. isCancelled)
104
+ XCTAssertTrue ( task. isCancelled)
91
105
}
92
106
93
107
func testRegistrationAfterCancellation( ) async throws {
94
108
let source = CancellationSource ( )
95
109
let task = Task { try await Task . sleep ( seconds: 10 ) }
96
110
source. cancel ( )
97
111
source. register ( task: task)
98
- try await waitUntil ( task, timeout: 5 ) { $0. isCancelled }
112
+ try await source. wait ( forSeconds: 5 )
113
+ XCTAssertTrue ( source. isCancelled)
114
+ XCTAssertTrue ( task. isCancelled)
99
115
}
100
116
101
117
func testMultipleTaskCancellation( ) async throws {
@@ -107,9 +123,11 @@ class CancellationSourceTests: XCTestCase {
107
123
source. register ( task: task2)
108
124
source. register ( task: task3)
109
125
source. cancel ( )
110
- try await waitUntil ( task1, timeout: 5 ) { $0. isCancelled }
111
- try await waitUntil ( task2, timeout: 5 ) { $0. isCancelled }
112
- try await waitUntil ( task3, timeout: 5 ) { $0. isCancelled }
126
+ try await source. wait ( forSeconds: 5 )
127
+ XCTAssertTrue ( source. isCancelled)
128
+ XCTAssertTrue ( task1. isCancelled)
129
+ XCTAssertTrue ( task2. isCancelled)
130
+ XCTAssertTrue ( task3. isCancelled)
113
131
}
114
132
}
115
133
@@ -125,7 +143,9 @@ class CancellationSourceInitializationTests: XCTestCase {
125
143
} catch { }
126
144
}
127
145
source. cancel ( )
128
- try await waitUntil ( task, timeout: 5 ) { $0. isCancelled }
146
+ try await source. wait ( forSeconds: 5 )
147
+ XCTAssertTrue ( source. isCancelled)
148
+ XCTAssertTrue ( task. isCancelled)
129
149
}
130
150
131
151
func testDetachedTaskCancellation( ) async throws {
@@ -137,7 +157,9 @@ class CancellationSourceInitializationTests: XCTestCase {
137
157
} catch { }
138
158
}
139
159
source. cancel ( )
140
- try await waitUntil ( task, timeout: 5 ) { $0. isCancelled }
160
+ try await source. wait ( forSeconds: 5 )
161
+ XCTAssertTrue ( source. isCancelled)
162
+ XCTAssertTrue ( task. isCancelled)
141
163
}
142
164
143
165
func testThrowingTaskCancellation( ) async throws {
@@ -146,7 +168,9 @@ class CancellationSourceInitializationTests: XCTestCase {
146
168
try await Task . sleep ( seconds: 10 )
147
169
}
148
170
source. cancel ( )
149
- try await waitUntil ( task, timeout: 5 ) { $0. isCancelled }
171
+ try await source. wait ( forSeconds: 5 )
172
+ XCTAssertTrue ( source. isCancelled)
173
+ XCTAssertTrue ( task. isCancelled)
150
174
}
151
175
152
176
func testThrowingDetachedTaskCancellation( ) async throws {
@@ -155,6 +179,8 @@ class CancellationSourceInitializationTests: XCTestCase {
155
179
try await Task . sleep ( seconds: 10 )
156
180
}
157
181
source. cancel ( )
158
- try await waitUntil ( task, timeout: 5 ) { $0. isCancelled }
182
+ try await source. wait ( forSeconds: 5 )
183
+ XCTAssertTrue ( source. isCancelled)
184
+ XCTAssertTrue ( task. isCancelled)
159
185
}
160
186
}
0 commit comments