@@ -14,11 +14,9 @@ final class DeadlineTests: XCTestCase {
14
14
}
15
15
16
16
await testClock. advance ( by: . milliseconds( 200 ) )
17
- do {
18
- try await task. value
19
- } catch {
20
- XCTFail ( )
21
- }
17
+
18
+ let result = await task. result
19
+ XCTAssertNoThrow ( try result. get ( ) )
22
20
}
23
21
24
22
func testDeadline( ) async {
@@ -31,13 +29,10 @@ final class DeadlineTests: XCTestCase {
31
29
}
32
30
33
31
await testClock. advance ( by: . milliseconds( 200 ) )
34
- do {
35
- try await task. value
36
- XCTFail ( )
37
- } catch is DeadlineExceededError {
38
- // expected
39
- } catch {
40
- XCTFail ( )
32
+
33
+ let result = await task. result
34
+ XCTAssertThrowsError ( try result. get ( ) ) { error in
35
+ XCTAssertTrue ( error is DeadlineExceededError )
41
36
}
42
37
}
43
38
@@ -59,13 +54,9 @@ final class DeadlineTests: XCTestCase {
59
54
await testClock. advance ( by: . milliseconds( 50 ) )
60
55
task. cancel ( )
61
56
62
- do {
63
- try await task. value
64
- XCTFail ( )
65
- } catch is CustomError {
66
- // expected
67
- } catch {
68
- XCTFail ( )
57
+ let result = await task. result
58
+ XCTAssertThrowsError ( try result. get ( ) ) { error in
59
+ XCTAssertTrue ( error is CustomError )
69
60
}
70
61
}
71
62
@@ -86,13 +77,32 @@ final class DeadlineTests: XCTestCase {
86
77
87
78
task. cancel ( )
88
79
89
- do {
90
- try await task. value
91
- XCTFail ( )
92
- } catch is CustomError {
93
- // expected
94
- } catch {
95
- XCTFail ( )
80
+ let result = await task. result
81
+ XCTAssertThrowsError ( try result. get ( ) ) { error in
82
+ XCTAssertTrue ( error is CustomError )
83
+ }
84
+ }
85
+
86
+ func testFailingClock( ) async {
87
+
88
+ struct CustomError : Error { }
89
+ struct CustomClock : Clock {
90
+ let _internal = TestClock ( )
91
+ var now : TestClock < Duration > . Instant { _internal. now }
92
+ var minimumResolution : TestClock < Duration > . Duration { _internal. minimumResolution }
93
+ func sleep( until deadline: Instant , tolerance: Duration ? = nil ) async throws { throw CustomError ( ) }
94
+ }
95
+
96
+ let customClock = CustomClock ( )
97
+ let task = Task {
98
+ try await withDeadline ( until: . init( offset: . milliseconds( 200 ) ) , clock: customClock) {
99
+ try await customClock. sleep ( until: . init( offset: . milliseconds( 100 ) ) )
100
+ }
101
+ }
102
+
103
+ let result = await task. result
104
+ XCTAssertThrowsError ( try result. get ( ) ) { error in
105
+ XCTAssertTrue ( error is CustomError )
96
106
}
97
107
}
98
108
}
0 commit comments