Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 156bb4b

Browse files
authored
Reduce the overall warnings from tests (apple#274)
* Migrate from semaphore style testing waits to async test fulfillment * Reduce warnings for missing hashable and comparable conformances per availability * Reduce warnings for executor (still one known warning)
1 parent 936a68d commit 156bb4b

18 files changed

+67
-56
lines changed

Sources/AsyncSequenceValidation/Clock.swift

+4
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,7 @@ extension AsyncSequenceValidationDiagram.Clock: TestClock { }
132132

133133
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
134134
extension AsyncSequenceValidationDiagram.Clock: Clock { }
135+
136+
// placeholders to avoid warnings
137+
extension AsyncSequenceValidationDiagram.Clock.Instant: Hashable { }
138+
extension AsyncSequenceValidationDiagram.Clock.Instant: Comparable { }

Sources/AsyncSequenceValidation/Test.swift

+6
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ extension AsyncSequenceValidationDiagram {
6868

6969
struct Context {
7070
final class ClockExecutor: SerialExecutor {
71+
@available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *)
72+
func enqueue(_ job: __owned ExecutorJob) {
73+
job.runSynchronously(on: asUnownedSerialExecutor())
74+
}
75+
76+
@available(*, deprecated) // known deprecation warning
7177
func enqueue(_ job: UnownedJob) {
7278
job._runSynchronously(on: asUnownedSerialExecutor())
7379
}

Tests/AsyncAlgorithmsTests/TestAdjacentPairs.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@ final class TestAdjacentPairs: XCTestCase {
8888
}
8989

9090
// ensure the other task actually starts
91-
wait(for: [iterated], timeout: 1.0)
91+
92+
await fulfillment(of: [iterated], timeout: 1.0)
9293
// cancellation should ensure the loop finishes
9394
// without regards to the remaining underlying sequence
9495
task.cancel()
95-
wait(for: [finished], timeout: 1.0)
96+
await fulfillment(of: [finished], timeout: 1.0)
9697
}
9798
}

Tests/AsyncAlgorithmsTests/TestBuffer.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,13 @@ final class TestBuffer: XCTestCase {
190190
finished.fulfill()
191191
}
192192
// ensure the task actually starts
193-
wait(for: [iterated], timeout: 1.0)
193+
await fulfillment(of: [iterated], timeout: 1.0)
194194

195195
// When
196196
task.cancel()
197197

198198
// Then
199-
wait(for: [finished], timeout: 1.0)
199+
await fulfillment(of: [finished], timeout: 1.0)
200200
}
201201

202202
func test_given_a_base_sequence_when_buffering_with_bounded_then_the_buffer_is_filled_in_and_suspends() async {
@@ -310,13 +310,13 @@ final class TestBuffer: XCTestCase {
310310
finished.fulfill()
311311
}
312312
// ensure the other task actually starts
313-
wait(for: [iterated], timeout: 1.0)
313+
await fulfillment(of: [iterated], timeout: 1.0)
314314

315315
// When
316316
task.cancel()
317317

318318
// Then
319-
wait(for: [finished], timeout: 1.0)
319+
await fulfillment(of: [finished], timeout: 1.0)
320320
}
321321

322322
func test_given_a_base_sequence_when_bounded_with_limit_0_then_the_policy_is_transparent() async {

Tests/AsyncAlgorithmsTests/TestBufferedByteIterator.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ final class TestBufferedByteIterator: XCTestCase {
199199
}
200200
}
201201
}
202-
wait(for: [iterated], timeout: 1.0)
202+
await fulfillment(of: [iterated], timeout: 1.0)
203203
// cancellation should ensure the loop finishes
204204
// without regards to the remaining underlying sequence
205205
task.cancel()
206-
wait(for: [finished], timeout: 1.0)
206+
await fulfillment(of: [finished], timeout: 1.0)
207207
}
208208
}

Tests/AsyncAlgorithmsTests/TestChain.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ final class TestChain2: XCTestCase {
8787
}
8888

8989
// ensure the other task actually starts
90-
wait(for: [iterated], timeout: 1.0)
90+
await fulfillment(of: [iterated], timeout: 1.0)
9191

9292
// cancellation should ensure the loop finishes
9393
// without regards to the remaining underlying sequence
9494
task.cancel()
9595

96-
wait(for: [finished], timeout: 1.0)
96+
await fulfillment(of: [finished], timeout: 1.0)
9797
}
9898
}
9999

@@ -192,12 +192,12 @@ final class TestChain3: XCTestCase {
192192
}
193193

194194
// ensure the other task actually starts
195-
wait(for: [iterated], timeout: 1.0)
195+
await fulfillment(of: [iterated], timeout: 1.0)
196196

197197
// cancellation should ensure the loop finishes
198198
// without regards to the remaining underlying sequence
199199
task.cancel()
200200

201-
wait(for: [finished], timeout: 1.0)
201+
await fulfillment(of: [finished], timeout: 1.0)
202202
}
203203
}

Tests/AsyncAlgorithmsTests/TestChannel.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ final class TestChannel: XCTestCase {
133133
task1.cancel()
134134

135135
// Then: the first sending operation is resumed
136-
wait(for: [send1IsResumed], timeout: 1.0)
136+
await fulfillment(of: [send1IsResumed], timeout: 1.0)
137137

138138
// When: collecting elements
139139
var iterator = sut.makeAsyncIterator()

Tests/AsyncAlgorithmsTests/TestCombineLatest.swift

+9-9
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ final class TestCombineLatest2: XCTestCase {
8484
value = await validator.validate()
8585
XCTAssertEqual(value, [(1, "a"), (2, "a"), (2, "b"), (3, "b"), (3, "c")])
8686

87-
wait(for: [finished], timeout: 1.0)
87+
await fulfillment(of: [finished], timeout: 1.0)
8888
value = validator.current
8989
XCTAssertEqual(value, [(1, "a"), (2, "a"), (2, "b"), (3, "b"), (3, "c")])
9090
}
@@ -126,7 +126,7 @@ final class TestCombineLatest2: XCTestCase {
126126
value = await validator.validate()
127127
XCTAssertEqual(value, [(1, "a"), (1, "b"), (2, "b"), (2, "c"), (3, "c")])
128128

129-
wait(for: [finished], timeout: 1.0)
129+
await fulfillment(of: [finished], timeout: 1.0)
130130
value = validator.current
131131
XCTAssertEqual(value, [(1, "a"), (1, "b"), (2, "b"), (2, "c"), (3, "c")])
132132
}
@@ -168,7 +168,7 @@ final class TestCombineLatest2: XCTestCase {
168168
value = await validator.validate()
169169
XCTAssertEqual(value, [(1, "a"), (2, "a"), (3, "a"), (3, "b"), (3, "c")])
170170

171-
wait(for: [finished], timeout: 1.0)
171+
await fulfillment(of: [finished], timeout: 1.0)
172172
value = validator.current
173173
XCTAssertEqual(value, [(1, "a"), (2, "a"), (3, "a"), (3, "b"), (3, "c")])
174174
}
@@ -210,7 +210,7 @@ final class TestCombineLatest2: XCTestCase {
210210
value = await validator.validate()
211211
XCTAssertEqual(value, [(1, "a"), (1, "b"), (1, "c"), (2, "c"), (3, "c")])
212212

213-
wait(for: [finished], timeout: 1.0)
213+
await fulfillment(of: [finished], timeout: 1.0)
214214
value = validator.current
215215
XCTAssertEqual(value, [(1, "a"), (1, "b"), (1, "c"), (2, "c"), (3, "c")])
216216
}
@@ -250,7 +250,7 @@ final class TestCombineLatest2: XCTestCase {
250250

251251
XCTAssertEqual(validator.failure as? Failure, Failure())
252252

253-
wait(for: [finished], timeout: 1.0)
253+
await fulfillment(of: [finished], timeout: 1.0)
254254
value = validator.current
255255
XCTAssertEqual(value, [(1, "a"), (1, "b")])
256256
}
@@ -290,7 +290,7 @@ final class TestCombineLatest2: XCTestCase {
290290

291291
XCTAssertEqual(validator.failure as? Failure, Failure())
292292

293-
wait(for: [finished], timeout: 1.0)
293+
await fulfillment(of: [finished], timeout: 1.0)
294294
value = validator.current
295295
XCTAssertEqual(value, [(1, "a"), (2, "a")])
296296
}
@@ -312,11 +312,11 @@ final class TestCombineLatest2: XCTestCase {
312312
finished.fulfill()
313313
}
314314
// ensure the other task actually starts
315-
wait(for: [iterated], timeout: 1.0)
315+
await fulfillment(of: [iterated], timeout: 1.0)
316316
// cancellation should ensure the loop finishes
317317
// without regards to the remaining underlying sequence
318318
task.cancel()
319-
wait(for: [finished], timeout: 1.0)
319+
await fulfillment(of: [finished], timeout: 1.0)
320320
}
321321

322322
func test_combineLatest_when_cancelled() async {
@@ -389,7 +389,7 @@ final class TestCombineLatest3: XCTestCase {
389389
value = await validator.validate()
390390
XCTAssertEqual(value, [(1, "a", 4), (2, "a", 4), (2, "b", 4), (2, "b", 5), (3, "b", 5), (3, "c", 5), (3, "c", 6)])
391391

392-
wait(for: [finished], timeout: 1.0)
392+
await fulfillment(of: [finished], timeout: 1.0)
393393
value = validator.current
394394
XCTAssertEqual(value, [(1, "a", 4), (2, "a", 4), (2, "b", 4), (2, "b", 5), (3, "b", 5), (3, "c", 5), (3, "c", 6)])
395395
}

Tests/AsyncAlgorithmsTests/TestCompacted.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ final class TestCompacted: XCTestCase {
8383
finished.fulfill()
8484
}
8585
// ensure the other task actually starts
86-
wait(for: [iterated], timeout: 1.0)
86+
await fulfillment(of: [iterated], timeout: 1.0)
8787
// cancellation should ensure the loop finishes
8888
// without regards to the remaining underlying sequence
8989
task.cancel()
90-
wait(for: [finished], timeout: 1.0)
90+
await fulfillment(of: [finished], timeout: 1.0)
9191
}
9292
}

Tests/AsyncAlgorithmsTests/TestJoin.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ final class TestJoinedBySeparator: XCTestCase {
122122
finished.fulfill()
123123
}
124124
// ensure the other task actually starts
125-
wait(for: [iterated], timeout: 1.0)
125+
await fulfillment(of: [iterated], timeout: 1.0)
126126
// cancellation should ensure the loop finishes
127127
// without regards to the remaining underlying sequence
128128
task.cancel()
129-
wait(for: [finished], timeout: 1.0)
129+
await fulfillment(of: [finished], timeout: 1.0)
130130
}
131131
}
132132

@@ -206,10 +206,10 @@ final class TestJoined: XCTestCase {
206206
finished.fulfill()
207207
}
208208
// ensure the other task actually starts
209-
wait(for: [iterated], timeout: 1.0)
209+
await fulfillment(of: [iterated], timeout: 1.0)
210210
// cancellation should ensure the loop finishes
211211
// without regards to the remaining underlying sequence
212212
task.cancel()
213-
wait(for: [finished], timeout: 1.0)
213+
await fulfillment(of: [finished], timeout: 1.0)
214214
}
215215
}

Tests/AsyncAlgorithmsTests/TestLazy.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ final class TestLazy: XCTestCase {
121121
}
122122

123123
// ensure the other task actually starts
124-
wait(for: [iterated], timeout: 1.0)
124+
await fulfillment(of: [iterated], timeout: 1.0)
125125

126126
// cancellation should ensure the loop finishes
127127
// without regards to the remaining underlying sequence
128128
task.cancel()
129129

130-
wait(for: [finished], timeout: 1.0)
130+
await fulfillment(of: [finished], timeout: 1.0)
131131
}
132132
}

Tests/AsyncAlgorithmsTests/TestManualClock.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class TestManualClock: XCTestCase {
2929
clock.advance()
3030
XCTAssertFalse(state.withCriticalRegion { $0 })
3131
clock.advance()
32-
wait(for: [afterSleep], timeout: 1.0)
32+
await fulfillment(of: [afterSleep], timeout: 1.0)
3333
XCTAssertTrue(state.withCriticalRegion { $0 })
3434
}
3535

@@ -51,7 +51,7 @@ final class TestManualClock: XCTestCase {
5151
XCTAssertFalse(state.withCriticalRegion { $0 })
5252
clock.advance()
5353
task.cancel()
54-
wait(for: [afterSleep], timeout: 1.0)
54+
await fulfillment(of: [afterSleep], timeout: 1.0)
5555
XCTAssertTrue(state.withCriticalRegion { $0 })
5656
XCTAssertTrue(failure.withCriticalRegion { $0 is CancellationError })
5757
}
@@ -73,7 +73,7 @@ final class TestManualClock: XCTestCase {
7373
}
7474
XCTAssertFalse(state.withCriticalRegion { $0 })
7575
task.cancel()
76-
wait(for: [afterSleep], timeout: 1.0)
76+
await fulfillment(of: [afterSleep], timeout: 1.0)
7777
XCTAssertTrue(state.withCriticalRegion { $0 })
7878
XCTAssertTrue(failure.withCriticalRegion { $0 is CancellationError })
7979
}

Tests/AsyncAlgorithmsTests/TestMerge.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@ final class TestMerge2: XCTestCase {
185185
finished.fulfill()
186186
}
187187
// ensure the other task actually starts
188-
wait(for: [iterated], timeout: 1.0)
188+
await fulfillment(of: [iterated], timeout: 1.0)
189189
// cancellation should ensure the loop finishes
190190
// without regards to the remaining underlying sequence
191191
task.cancel()
192-
wait(for: [finished], timeout: 1.0)
192+
await fulfillment(of: [finished], timeout: 1.0)
193193
}
194194

195195
func test_merge_when_cancelled() async {
@@ -509,11 +509,11 @@ final class TestMerge3: XCTestCase {
509509
finished.fulfill()
510510
}
511511
// ensure the other task actually starts
512-
wait(for: [iterated], timeout: 1.0)
512+
await fulfillment(of: [iterated], timeout: 1.0)
513513
// cancellation should ensure the loop finishes
514514
// without regards to the remaining underlying sequence
515515
task.cancel()
516-
wait(for: [finished], timeout: 1.0)
516+
await fulfillment(of: [finished], timeout: 1.0)
517517
}
518518

519519
// MARK: - IteratorInitialized

Tests/AsyncAlgorithmsTests/TestReductions.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,10 @@ final class TestReductions: XCTestCase {
217217
finished.fulfill()
218218
}
219219
// ensure the other task actually starts
220-
wait(for: [iterated], timeout: 1.0)
220+
await fulfillment(of: [iterated], timeout: 1.0)
221221
// cancellation should ensure the loop finishes
222222
// without regards to the remaining underlying sequence
223223
task.cancel()
224-
wait(for: [finished], timeout: 1.0)
224+
await fulfillment(of: [finished], timeout: 1.0)
225225
}
226226
}

Tests/AsyncAlgorithmsTests/TestRemoveDuplicates.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ final class TestRemoveDuplicates: XCTestCase {
9595
finished.fulfill()
9696
}
9797
// ensure the other task actually starts
98-
wait(for: [iterated], timeout: 1.0)
98+
await fulfillment(of: [iterated], timeout: 1.0)
9999
// cancellation should ensure the loop finishes
100100
// without regards to the remaining underlying sequence
101101
task.cancel()
102-
wait(for: [finished], timeout: 1.0)
102+
await fulfillment(of: [finished], timeout: 1.0)
103103
}
104104
}

Tests/AsyncAlgorithmsTests/TestThrowingChannel.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ final class TestThrowingChannel: XCTestCase {
270270
task1.cancel()
271271

272272
// Then: the first sending operation is resumed
273-
wait(for: [send1IsResumed], timeout: 1.0)
273+
await fulfillment(of: [send1IsResumed], timeout: 1.0)
274274

275275
// When: collecting elements
276276
var iterator = sut.makeAsyncIterator()

0 commit comments

Comments
 (0)