Reduce the overall warnings from tests (#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)
This commit is contained in:
Philippe Hausler authored and GitHub committed 2023-06-23 12:22:23 -07:00
1 parent 936a68d012
commit 156bb4bf49
18 files changed
+67 -56

No files matched your search

@@ -132,3 +132,7 @@ extension AsyncSequenceValidationDiagram.Clock: TestClock { }
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
extension AsyncSequenceValidationDiagram.Clock: Clock { }
// placeholders to avoid warnings
extension AsyncSequenceValidationDiagram.Clock.Instant: Hashable { }
extension AsyncSequenceValidationDiagram.Clock.Instant: Comparable { }
@@ -68,6 +68,12 @@ extension AsyncSequenceValidationDiagram {
struct Context {
final class ClockExecutor: SerialExecutor {
@available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *)
func enqueue(_ job: __owned ExecutorJob) {
job.runSynchronously(on: asUnownedSerialExecutor())
}
@available(*, deprecated) // known deprecation warning
func enqueue(_ job: UnownedJob) {
job._runSynchronously(on: asUnownedSerialExecutor())
}
@@ -88,10 +88,11 @@ final class TestAdjacentPairs: XCTestCase {
}
// ensure the other task actually starts
wait(for: [iterated], timeout: 1.0)
await fulfillment(of: [iterated], timeout: 1.0)
// cancellation should ensure the loop finishes
// without regards to the remaining underlying sequence
task.cancel()
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
}
}
+4 -4
View File
@@ -190,13 +190,13 @@ final class TestBuffer: XCTestCase {
finished.fulfill()
}
// ensure the task actually starts
wait(for: [iterated], timeout: 1.0)
await fulfillment(of: [iterated], timeout: 1.0)
// When
task.cancel()
// Then
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
}
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 {
finished.fulfill()
}
// ensure the other task actually starts
wait(for: [iterated], timeout: 1.0)
await fulfillment(of: [iterated], timeout: 1.0)
// When
task.cancel()
// Then
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
}
func test_given_a_base_sequence_when_bounded_with_limit_0_then_the_policy_is_transparent() async {
@@ -199,10 +199,10 @@ final class TestBufferedByteIterator: XCTestCase {
}
}
}
wait(for: [iterated], timeout: 1.0)
await fulfillment(of: [iterated], timeout: 1.0)
// cancellation should ensure the loop finishes
// without regards to the remaining underlying sequence
task.cancel()
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
}
}
+4 -4
View File
@@ -87,13 +87,13 @@ final class TestChain2: XCTestCase {
}
// ensure the other task actually starts
wait(for: [iterated], timeout: 1.0)
await fulfillment(of: [iterated], timeout: 1.0)
// cancellation should ensure the loop finishes
// without regards to the remaining underlying sequence
task.cancel()
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
}
}
@@ -192,12 +192,12 @@ final class TestChain3: XCTestCase {
}
// ensure the other task actually starts
wait(for: [iterated], timeout: 1.0)
await fulfillment(of: [iterated], timeout: 1.0)
// cancellation should ensure the loop finishes
// without regards to the remaining underlying sequence
task.cancel()
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
}
}
+1 -1
View File
@@ -133,7 +133,7 @@ final class TestChannel: XCTestCase {
task1.cancel()
// Then: the first sending operation is resumed
wait(for: [send1IsResumed], timeout: 1.0)
await fulfillment(of: [send1IsResumed], timeout: 1.0)
// When: collecting elements
var iterator = sut.makeAsyncIterator()
@@ -84,7 +84,7 @@ final class TestCombineLatest2: XCTestCase {
value = await validator.validate()
XCTAssertEqual(value, [(1, "a"), (2, "a"), (2, "b"), (3, "b"), (3, "c")])
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
value = validator.current
XCTAssertEqual(value, [(1, "a"), (2, "a"), (2, "b"), (3, "b"), (3, "c")])
}
@@ -126,7 +126,7 @@ final class TestCombineLatest2: XCTestCase {
value = await validator.validate()
XCTAssertEqual(value, [(1, "a"), (1, "b"), (2, "b"), (2, "c"), (3, "c")])
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
value = validator.current
XCTAssertEqual(value, [(1, "a"), (1, "b"), (2, "b"), (2, "c"), (3, "c")])
}
@@ -168,7 +168,7 @@ final class TestCombineLatest2: XCTestCase {
value = await validator.validate()
XCTAssertEqual(value, [(1, "a"), (2, "a"), (3, "a"), (3, "b"), (3, "c")])
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
value = validator.current
XCTAssertEqual(value, [(1, "a"), (2, "a"), (3, "a"), (3, "b"), (3, "c")])
}
@@ -210,7 +210,7 @@ final class TestCombineLatest2: XCTestCase {
value = await validator.validate()
XCTAssertEqual(value, [(1, "a"), (1, "b"), (1, "c"), (2, "c"), (3, "c")])
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
value = validator.current
XCTAssertEqual(value, [(1, "a"), (1, "b"), (1, "c"), (2, "c"), (3, "c")])
}
@@ -250,7 +250,7 @@ final class TestCombineLatest2: XCTestCase {
XCTAssertEqual(validator.failure as? Failure, Failure())
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
value = validator.current
XCTAssertEqual(value, [(1, "a"), (1, "b")])
}
@@ -290,7 +290,7 @@ final class TestCombineLatest2: XCTestCase {
XCTAssertEqual(validator.failure as? Failure, Failure())
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
value = validator.current
XCTAssertEqual(value, [(1, "a"), (2, "a")])
}
@@ -312,11 +312,11 @@ final class TestCombineLatest2: XCTestCase {
finished.fulfill()
}
// ensure the other task actually starts
wait(for: [iterated], timeout: 1.0)
await fulfillment(of: [iterated], timeout: 1.0)
// cancellation should ensure the loop finishes
// without regards to the remaining underlying sequence
task.cancel()
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
}
func test_combineLatest_when_cancelled() async {
@@ -389,7 +389,7 @@ final class TestCombineLatest3: XCTestCase {
value = await validator.validate()
XCTAssertEqual(value, [(1, "a", 4), (2, "a", 4), (2, "b", 4), (2, "b", 5), (3, "b", 5), (3, "c", 5), (3, "c", 6)])
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
value = validator.current
XCTAssertEqual(value, [(1, "a", 4), (2, "a", 4), (2, "b", 4), (2, "b", 5), (3, "b", 5), (3, "c", 5), (3, "c", 6)])
}
@@ -83,10 +83,10 @@ final class TestCompacted: XCTestCase {
finished.fulfill()
}
// ensure the other task actually starts
wait(for: [iterated], timeout: 1.0)
await fulfillment(of: [iterated], timeout: 1.0)
// cancellation should ensure the loop finishes
// without regards to the remaining underlying sequence
task.cancel()
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
}
}
+4 -4
View File
@@ -122,11 +122,11 @@ final class TestJoinedBySeparator: XCTestCase {
finished.fulfill()
}
// ensure the other task actually starts
wait(for: [iterated], timeout: 1.0)
await fulfillment(of: [iterated], timeout: 1.0)
// cancellation should ensure the loop finishes
// without regards to the remaining underlying sequence
task.cancel()
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
}
}
@@ -206,10 +206,10 @@ final class TestJoined: XCTestCase {
finished.fulfill()
}
// ensure the other task actually starts
wait(for: [iterated], timeout: 1.0)
await fulfillment(of: [iterated], timeout: 1.0)
// cancellation should ensure the loop finishes
// without regards to the remaining underlying sequence
task.cancel()
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
}
}
+2 -2
View File
@@ -121,12 +121,12 @@ final class TestLazy: XCTestCase {
}
// ensure the other task actually starts
wait(for: [iterated], timeout: 1.0)
await fulfillment(of: [iterated], timeout: 1.0)
// cancellation should ensure the loop finishes
// without regards to the remaining underlying sequence
task.cancel()
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
}
}
@@ -29,7 +29,7 @@ final class TestManualClock: XCTestCase {
clock.advance()
XCTAssertFalse(state.withCriticalRegion { $0 })
clock.advance()
wait(for: [afterSleep], timeout: 1.0)
await fulfillment(of: [afterSleep], timeout: 1.0)
XCTAssertTrue(state.withCriticalRegion { $0 })
}
@@ -51,7 +51,7 @@ final class TestManualClock: XCTestCase {
XCTAssertFalse(state.withCriticalRegion { $0 })
clock.advance()
task.cancel()
wait(for: [afterSleep], timeout: 1.0)
await fulfillment(of: [afterSleep], timeout: 1.0)
XCTAssertTrue(state.withCriticalRegion { $0 })
XCTAssertTrue(failure.withCriticalRegion { $0 is CancellationError })
}
@@ -73,7 +73,7 @@ final class TestManualClock: XCTestCase {
}
XCTAssertFalse(state.withCriticalRegion { $0 })
task.cancel()
wait(for: [afterSleep], timeout: 1.0)
await fulfillment(of: [afterSleep], timeout: 1.0)
XCTAssertTrue(state.withCriticalRegion { $0 })
XCTAssertTrue(failure.withCriticalRegion { $0 is CancellationError })
}
+4 -4
View File
@@ -185,11 +185,11 @@ final class TestMerge2: XCTestCase {
finished.fulfill()
}
// ensure the other task actually starts
wait(for: [iterated], timeout: 1.0)
await fulfillment(of: [iterated], timeout: 1.0)
// cancellation should ensure the loop finishes
// without regards to the remaining underlying sequence
task.cancel()
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
}
func test_merge_when_cancelled() async {
@@ -509,11 +509,11 @@ final class TestMerge3: XCTestCase {
finished.fulfill()
}
// ensure the other task actually starts
wait(for: [iterated], timeout: 1.0)
await fulfillment(of: [iterated], timeout: 1.0)
// cancellation should ensure the loop finishes
// without regards to the remaining underlying sequence
task.cancel()
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
}
// MARK: - IteratorInitialized
@@ -217,10 +217,10 @@ final class TestReductions: XCTestCase {
finished.fulfill()
}
// ensure the other task actually starts
wait(for: [iterated], timeout: 1.0)
await fulfillment(of: [iterated], timeout: 1.0)
// cancellation should ensure the loop finishes
// without regards to the remaining underlying sequence
task.cancel()
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
}
}
@@ -95,10 +95,10 @@ final class TestRemoveDuplicates: XCTestCase {
finished.fulfill()
}
// ensure the other task actually starts
wait(for: [iterated], timeout: 1.0)
await fulfillment(of: [iterated], timeout: 1.0)
// cancellation should ensure the loop finishes
// without regards to the remaining underlying sequence
task.cancel()
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
}
}
@@ -270,7 +270,7 @@ final class TestThrowingChannel: XCTestCase {
task1.cancel()
// Then: the first sending operation is resumed
wait(for: [send1IsResumed], timeout: 1.0)
await fulfillment(of: [send1IsResumed], timeout: 1.0)
// When: collecting elements
var iterator = sut.makeAsyncIterator()
+10 -10
View File
@@ -24,7 +24,7 @@ final class TestValidator: XCTestCase {
}
XCTAssertFalse(state.withCriticalRegion { $0 })
gate.open()
wait(for: [entered], timeout: 1.0)
await fulfillment(of: [entered], timeout: 1.0)
XCTAssertTrue(state.withCriticalRegion { $0 })
}
@@ -52,18 +52,18 @@ final class TestValidator: XCTestCase {
}
finished.fulfill()
}
wait(for: [started], timeout: 1.0)
await fulfillment(of: [started], timeout: 1.0)
XCTAssertEqual(state.withCriticalRegion { $0 }, [])
gated.advance()
wait(for: [expectations[0]], timeout: 1.0)
await fulfillment(of: [expectations[0]], timeout: 1.0)
XCTAssertEqual(state.withCriticalRegion { $0 }, [1])
gated.advance()
wait(for: [expectations[1]], timeout: 1.0)
await fulfillment(of: [expectations[1]], timeout: 1.0)
XCTAssertEqual(state.withCriticalRegion { $0 }, [1, 2])
gated.advance()
wait(for: [expectations[2]], timeout: 1.0)
await fulfillment(of: [expectations[2]], timeout: 1.0)
XCTAssertEqual(state.withCriticalRegion { $0 }, [1, 2, 3])
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
}
func test_gatedSequence_throwing() async {
@@ -93,14 +93,14 @@ final class TestValidator: XCTestCase {
}
finished.fulfill()
}
wait(for: [started], timeout: 1.0)
await fulfillment(of: [started], timeout: 1.0)
XCTAssertEqual(state.withCriticalRegion { $0 }, [])
gated.advance()
wait(for: [expectations[0]], timeout: 1.0)
await fulfillment(of: [expectations[0]], timeout: 1.0)
XCTAssertEqual(state.withCriticalRegion { $0 }, [1])
gated.advance()
XCTAssertEqual(state.withCriticalRegion { $0 }, [1])
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
XCTAssertEqual(state.withCriticalRegion { $0 }, [1])
XCTAssertEqual(failure.withCriticalRegion { $0 as? Failure }, Failure())
}
@@ -131,7 +131,7 @@ final class TestValidator: XCTestCase {
XCTAssertEqual(value, [2, 3, 4])
a.advance()
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
value = validator.current
XCTAssertEqual(value, [2, 3, 4])
}
+4 -4
View File
@@ -152,11 +152,11 @@ final class TestZip2: XCTestCase {
finished.fulfill()
}
// ensure the other task actually starts
wait(for: [iterated], timeout: 1.0)
await fulfillment(of: [iterated], timeout: 1.0)
// cancellation should ensure the loop finishes
// without regards to the remaining underlying sequence
task.cancel()
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
}
func test_zip_when_cancelled() async {
@@ -370,10 +370,10 @@ final class TestZip3: XCTestCase {
finished.fulfill()
}
// ensure the other task actually starts
wait(for: [iterated], timeout: 1.0)
await fulfillment(of: [iterated], timeout: 1.0)
// cancellation should ensure the loop finishes
// without regards to the remaining underlying sequence
task.cancel()
wait(for: [finished], timeout: 1.0)
await fulfillment(of: [finished], timeout: 1.0)
}
}