Skip to content

Commit ef93879

Browse files
committed
update to use await fulfillment(of:timeout:) testing API
1 parent 87791e0 commit ef93879

23 files changed

+160
-160
lines changed

Tests/AsyncChannels/AsyncBufferedChannelTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ final class AsyncBufferedChannelTests: XCTestCase {
4646
return received
4747
}
4848

49-
wait(for: [iterationIsAwaiting], timeout: 1.0)
49+
await fulfillment(of: [iterationIsAwaiting], timeout: 1.0)
5050

5151
// When
5252
sut.send(1)
@@ -125,19 +125,19 @@ final class AsyncBufferedChannelTests: XCTestCase {
125125
for await element in sut {
126126
received = element
127127
taskCanBeCancelled.fulfill()
128-
wait(for: [taskWasCancelled], timeout: 1.0)
128+
await fulfillment(of: [taskWasCancelled], timeout: 1.0)
129129
}
130130
iterationHasFinished.fulfill()
131131
return received
132132
}
133133

134-
wait(for: [taskCanBeCancelled], timeout: 1.0)
134+
await fulfillment(of: [taskCanBeCancelled], timeout: 1.0)
135135

136136
// When
137137
task.cancel()
138138
taskWasCancelled.fulfill()
139139

140-
wait(for: [iterationHasFinished], timeout: 1.0)
140+
await fulfillment(of: [iterationHasFinished], timeout: 1.0)
141141

142142
// Then
143143
let received = await task.value
@@ -170,12 +170,12 @@ final class AsyncBufferedChannelTests: XCTestCase {
170170
return received
171171
}
172172

173-
wait(for: [iteration1IsAwaiting, iteration2IsAwaiting], timeout: 1.0)
173+
await fulfillment(of: [iteration1IsAwaiting, iteration2IsAwaiting], timeout: 1.0)
174174

175175
// When
176176
sut.finish()
177177

178-
wait(for: [iteration1IsFinished, iteration2IsFinished], timeout: 1.0)
178+
await fulfillment(of: [iteration1IsFinished, iteration2IsFinished], timeout: 1.0)
179179

180180
let received1 = await task1.value
181181
let received2 = await task2.value
@@ -217,7 +217,7 @@ final class AsyncBufferedChannelTests: XCTestCase {
217217
}.cancel()
218218

219219
// Then
220-
wait(for: [iterationIsFinished], timeout: 1.0)
220+
await fulfillment(of: [iterationIsFinished], timeout: 1.0)
221221
}
222222

223223
func test_awaiting_uses_id_for_equatable() {

Tests/AsyncChannels/AsyncBufferedThrowingChannelTests.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ final class AsyncBufferedThrowingChannelTests: XCTestCase {
4646
return received
4747
}
4848

49-
wait(for: [iterationIsAwaiting], timeout: 1.0)
49+
await fulfillment(of: [iterationIsAwaiting], timeout: 1.0)
5050

5151
// When
5252
sut.send(1)
@@ -125,19 +125,19 @@ final class AsyncBufferedThrowingChannelTests: XCTestCase {
125125
for try await element in sut {
126126
received = element
127127
taskCanBeCancelled.fulfill()
128-
wait(for: [taskWasCancelled], timeout: 1.0)
128+
await fulfillment(of: [taskWasCancelled], timeout: 1.0)
129129
}
130130
iterationHasFinished.fulfill()
131131
return received
132132
}
133133

134-
wait(for: [taskCanBeCancelled], timeout: 1.0)
134+
await fulfillment(of: [taskCanBeCancelled], timeout: 1.0)
135135

136136
// When
137137
task.cancel()
138138
taskWasCancelled.fulfill()
139139

140-
wait(for: [iterationHasFinished], timeout: 1.0)
140+
await fulfillment(of: [iterationHasFinished], timeout: 1.0)
141141

142142
// Then
143143
let received = try await task.value
@@ -211,13 +211,13 @@ final class AsyncBufferedThrowingChannelTests: XCTestCase {
211211
}
212212
}
213213

214-
wait(for: [iteration1IsAwaiting, iteration2IsAwaiting], timeout: 1.0)
214+
await fulfillment(of: [iteration1IsAwaiting, iteration2IsAwaiting], timeout: 1.0)
215215

216216
// When
217217
sut.fail(MockError(code: 1701))
218218

219219
// Then
220-
wait(for: [iteration1HasThrown, iteration2HasThrown], timeout: 1.0)
220+
await fulfillment(of: [iteration1HasThrown, iteration2HasThrown], timeout: 1.0)
221221

222222
let iterator = sut.makeAsyncIterator()
223223
do {
@@ -254,12 +254,12 @@ final class AsyncBufferedThrowingChannelTests: XCTestCase {
254254
return received
255255
}
256256

257-
wait(for: [iteration1IsAwaiting, iteration2IsAwaiting], timeout: 1.0)
257+
await fulfillment(of: [iteration1IsAwaiting, iteration2IsAwaiting], timeout: 1.0)
258258

259259
// When
260260
sut.finish()
261261

262-
wait(for: [iteration1IsFinished, iteration2IsFinished], timeout: 1.0)
262+
await fulfillment(of: [iteration1IsFinished, iteration2IsFinished], timeout: 1.0)
263263

264264
let received1 = try await task1.value
265265
let received2 = try await task2.value
@@ -301,7 +301,7 @@ final class AsyncBufferedThrowingChannelTests: XCTestCase {
301301
}.cancel()
302302

303303
// Then
304-
wait(for: [iterationIsFinished], timeout: 1.0)
304+
await fulfillment(of: [iterationIsFinished], timeout: 1.0)
305305
}
306306

307307
func test_awaiting_uses_id_for_equatable() {

Tests/AsyncSubjets/AsyncCurrentValueSubjectTests.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ final class AsyncCurrentValueSubjectTests: XCTestCase {
3131
XCTAssertEqual(received2, 1)
3232
}
3333

34-
func test_send_pushes_values_in_the_subject() {
34+
func test_send_pushes_values_in_the_subject() async {
3535
let hasReceivedOneElementExpectation = expectation(description: "One element has been iterated in the async sequence")
3636
hasReceivedOneElementExpectation.expectedFulfillmentCount = 2
3737

@@ -72,12 +72,12 @@ final class AsyncCurrentValueSubjectTests: XCTestCase {
7272
}
7373
}
7474

75-
wait(for: [hasReceivedOneElementExpectation], timeout: 1)
75+
await fulfillment(of: [hasReceivedOneElementExpectation], timeout: 1)
7676

7777
sut.send(2)
7878
sut.value = 3
7979

80-
wait(for: [hasReceivedSentElementsExpectation], timeout: 1)
80+
await fulfillment(of: [hasReceivedSentElementsExpectation], timeout: 1)
8181
}
8282

8383
func test_sendFinished_ends_the_subject_and_immediately_resumes_futur_consumer() async {
@@ -107,18 +107,18 @@ final class AsyncCurrentValueSubjectTests: XCTestCase {
107107
hasFinishedExpectation.fulfill()
108108
}
109109

110-
wait(for: [hasReceivedOneElementExpectation], timeout: 1)
110+
await fulfillment(of: [hasReceivedOneElementExpectation], timeout: 1)
111111

112112
sut.send(.finished)
113113

114-
wait(for: [hasFinishedExpectation], timeout: 1)
114+
await fulfillment(of: [hasFinishedExpectation], timeout: 1)
115115

116116
var iterator = sut.makeAsyncIterator()
117117
let received = await iterator.next()
118118
XCTAssertNil(received)
119119
}
120120

121-
func test_subject_finishes_when_task_is_cancelled() {
121+
func test_subject_finishes_when_task_is_cancelled() async {
122122
let canCancelExpectation = expectation(description: "The first element has been emitted")
123123
let hasCancelExceptation = expectation(description: "The task has been cancelled")
124124
let taskHasFinishedExpectation = expectation(description: "The task has finished")
@@ -130,19 +130,19 @@ final class AsyncCurrentValueSubjectTests: XCTestCase {
130130
for await element in sut {
131131
firstElement = element
132132
canCancelExpectation.fulfill()
133-
wait(for: [hasCancelExceptation], timeout: 5)
133+
await fulfillment(of: [hasCancelExceptation], timeout: 5)
134134
}
135135
XCTAssertEqual(firstElement, 1)
136136
taskHasFinishedExpectation.fulfill()
137137
}
138138

139-
wait(for: [canCancelExpectation], timeout: 5) // one element has been emitted, we can cancel the task
139+
await fulfillment(of: [canCancelExpectation], timeout: 5) // one element has been emitted, we can cancel the task
140140

141141
task.cancel()
142142

143143
hasCancelExceptation.fulfill() // we can release the lock in the for loop
144144

145-
wait(for: [taskHasFinishedExpectation], timeout: 5) // task has been cancelled and has finished
145+
await fulfillment(of: [taskHasFinishedExpectation], timeout: 5) // task has been cancelled and has finished
146146
}
147147

148148
func test_subject_handles_concurrency() async throws {
@@ -175,7 +175,7 @@ final class AsyncCurrentValueSubjectTests: XCTestCase {
175175
return received.sorted()
176176
}
177177

178-
await waitForExpectations(timeout: 1)
178+
await fulfillment(of: [canSendExpectation], timeout: 1)
179179

180180
// concurrently push values in the sut 1
181181
let task1 = Task {

Tests/AsyncSubjets/AsyncPassthroughSubjectTests.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import XCTest
1010

1111
final class AsyncPassthroughSubjectTests: XCTestCase {
12-
func test_send_pushes_elements_in_the_subject() {
12+
func test_send_pushes_elements_in_the_subject() async {
1313
let isReadyToBeIteratedExpectation = expectation(description: "Passthrough subject iterators are ready for iteration")
1414
isReadyToBeIteratedExpectation.expectedFulfillmentCount = 2
1515

@@ -48,13 +48,13 @@ final class AsyncPassthroughSubjectTests: XCTestCase {
4848
}
4949
}
5050

51-
wait(for: [isReadyToBeIteratedExpectation], timeout: 1)
51+
await fulfillment(of: [isReadyToBeIteratedExpectation], timeout: 1)
5252

5353
sut.send(1)
5454
sut.send(2)
5555
sut.send(3)
5656

57-
wait(for: [hasReceivedSentElementsExpectation], timeout: 1)
57+
await fulfillment(of: [hasReceivedSentElementsExpectation], timeout: 1)
5858
}
5959

6060
func test_sendFinished_ends_the_subject_and_immediately_resumes_futur_consumer() async {
@@ -91,22 +91,22 @@ final class AsyncPassthroughSubjectTests: XCTestCase {
9191
hasFinishedExpectation.fulfill()
9292
}
9393

94-
wait(for: [isReadyToBeIteratedExpectation], timeout: 1)
94+
await fulfillment(of: [isReadyToBeIteratedExpectation], timeout: 1)
9595

9696
sut.send(1)
9797

98-
wait(for: [hasReceivedOneElementExpectation], timeout: 1)
98+
await fulfillment(of: [hasReceivedOneElementExpectation], timeout: 1)
9999

100100
sut.send( .finished)
101101

102-
wait(for: [hasFinishedExpectation], timeout: 1)
102+
await fulfillment(of: [hasFinishedExpectation], timeout: 1)
103103

104104
var iterator = sut.makeAsyncIterator()
105105
let received = await iterator.next()
106106
XCTAssertNil(received)
107107
}
108108

109-
func test_subject_finishes_when_task_is_cancelled() {
109+
func test_subject_finishes_when_task_is_cancelled() async {
110110
let isReadyToBeIteratedExpectation = expectation(description: "Passthrough subject iterators are ready for iteration")
111111
let canCancelExpectation = expectation(description: "The first element has been emitted")
112112
let hasCancelExpectation = expectation(description: "The task has been cancelled")
@@ -122,23 +122,23 @@ final class AsyncPassthroughSubjectTests: XCTestCase {
122122
while let element = await it.next() {
123123
receivedElements.append(element)
124124
canCancelExpectation.fulfill()
125-
wait(for: [hasCancelExpectation], timeout: 5)
125+
await fulfillment(of: [hasCancelExpectation], timeout: 5)
126126
}
127127
XCTAssertEqual(receivedElements, [1])
128128
taskHasFinishedExpectation.fulfill()
129129
}
130130

131-
wait(for: [isReadyToBeIteratedExpectation], timeout: 1)
131+
await fulfillment(of: [isReadyToBeIteratedExpectation], timeout: 1)
132132

133133
sut.send(1)
134134

135-
wait(for: [canCancelExpectation], timeout: 5) // one element has been emitted, we can cancel the task
135+
await fulfillment(of: [canCancelExpectation], timeout: 5) // one element has been emitted, we can cancel the task
136136

137137
task.cancel()
138138

139139
hasCancelExpectation.fulfill() // we can release the lock in the for loop
140140

141-
wait(for: [taskHasFinishedExpectation], timeout: 5) // task has been cancelled and has finished
141+
await fulfillment(of: [taskHasFinishedExpectation], timeout: 5) // task has been cancelled and has finished
142142
}
143143

144144
func test_subject_handles_concurrency() async {
@@ -171,7 +171,7 @@ final class AsyncPassthroughSubjectTests: XCTestCase {
171171
return received.sorted()
172172
}
173173

174-
await waitForExpectations(timeout: 1)
174+
await fulfillment(of: [canSendExpectation], timeout: 1)
175175

176176
// concurrently push values in the sut 1
177177
let task1 = Task {

Tests/AsyncSubjets/AsyncReplaySubjectTests.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import XCTest
1010

1111
final class AsyncReplaySubjectTests: XCTestCase {
12-
func test_send_replays_buffered_elements() {
12+
func test_send_replays_buffered_elements() async {
1313
let exp = expectation(description: "Send has stacked elements in the replay the buffer")
1414
exp.expectedFulfillmentCount = 2
1515

@@ -47,10 +47,10 @@ final class AsyncReplaySubjectTests: XCTestCase {
4747
}
4848
}
4949

50-
waitForExpectations(timeout: 0.5)
50+
await fulfillment(of: [exp], timeout: 0.5)
5151
}
5252

53-
func test_send_pushes_elements_in_the_subject() {
53+
func test_send_pushes_elements_in_the_subject() async {
5454
let hasReceivedOneElementExpectation = expectation(description: "One element has been iterated in the async sequence")
5555
hasReceivedOneElementExpectation.expectedFulfillmentCount = 2
5656

@@ -93,12 +93,12 @@ final class AsyncReplaySubjectTests: XCTestCase {
9393
}
9494
}
9595

96-
wait(for: [hasReceivedOneElementExpectation], timeout: 1)
96+
await fulfillment(of: [hasReceivedOneElementExpectation], timeout: 1)
9797

9898
sut.send(2)
9999
sut.send(3)
100100

101-
wait(for: [hasReceivedSentElementsExpectation], timeout: 1)
101+
await fulfillment(of: [hasReceivedSentElementsExpectation], timeout: 1)
102102
}
103103

104104
func test_sendFinished_ends_the_subject_and_immediately_resumes_futur_consumer() async {
@@ -130,18 +130,18 @@ final class AsyncReplaySubjectTests: XCTestCase {
130130
hasFinishedExpectation.fulfill()
131131
}
132132

133-
wait(for: [hasReceivedOneElementExpectation], timeout: 1)
133+
await fulfillment(of: [hasReceivedOneElementExpectation], timeout: 1)
134134

135135
sut.send(.finished)
136136

137-
wait(for: [hasFinishedExpectation], timeout: 1)
137+
await fulfillment(of: [hasFinishedExpectation], timeout: 1)
138138

139139
var iterator = sut.makeAsyncIterator()
140140
let received = await iterator.next()
141141
XCTAssertNil(received)
142142
}
143143

144-
func test_subject_finishes_when_task_is_cancelled() {
144+
func test_subject_finishes_when_task_is_cancelled() async {
145145
let canCancelExpectation = expectation(description: "The first element has been emitted")
146146
let hasCancelExceptation = expectation(description: "The task has been cancelled")
147147
let taskHasFinishedExpectation = expectation(description: "The task has finished")
@@ -155,19 +155,19 @@ final class AsyncReplaySubjectTests: XCTestCase {
155155
for await element in sut {
156156
firstElement = element
157157
canCancelExpectation.fulfill()
158-
wait(for: [hasCancelExceptation], timeout: 5)
158+
await fulfillment(of: [hasCancelExceptation], timeout: 5)
159159
}
160160
XCTAssertEqual(firstElement, 1)
161161
taskHasFinishedExpectation.fulfill()
162162
}
163163

164-
wait(for: [canCancelExpectation], timeout: 5) // one element has been emitted, we can cancel the task
164+
await fulfillment(of: [canCancelExpectation], timeout: 5) // one element has been emitted, we can cancel the task
165165

166166
task.cancel()
167167

168168
hasCancelExceptation.fulfill() // we can release the lock in the for loop
169169

170-
wait(for: [taskHasFinishedExpectation], timeout: 5) // task has been cancelled and has finished
170+
await fulfillment(of: [taskHasFinishedExpectation], timeout: 5) // task has been cancelled and has finished
171171
}
172172

173173
func test_subject_handles_concurrency() async {
@@ -200,7 +200,7 @@ final class AsyncReplaySubjectTests: XCTestCase {
200200
return received.sorted()
201201
}
202202

203-
await waitForExpectations(timeout: 1)
203+
await fulfillment(of: [canSendExpectation], timeout: 1)
204204

205205
// concurrently push values in the sut 1
206206
let task1 = Task {

0 commit comments

Comments
 (0)