@@ -27,6 +27,9 @@ typealias PreparedRequest = HTTPClientRequest.Prepared
27
27
final class TransactionTests : XCTestCase {
28
28
func testCancelAsyncRequest( ) {
29
29
guard #available( macOS 10 . 15 , iOS 13 . 0 , watchOS 6 . 0 , tvOS 13 . 0 , * ) else { return }
30
+ // creating the `XCTestExpectation` off the main thread crashes on Linux with Swift 5.6
31
+ // therefore we create it here as a workaround which works fine
32
+ let scheduledRequestCanceled = self . expectation ( description: " scheduled request canceled " )
30
33
XCTAsyncTest {
31
34
let embeddedEventLoop = EmbeddedEventLoop ( )
32
35
defer { XCTAssertNoThrow ( try embeddedEventLoop. syncShutdownGracefully ( ) ) }
@@ -43,19 +46,25 @@ final class TransactionTests: XCTestCase {
43
46
preferredEventLoop: embeddedEventLoop
44
47
)
45
48
46
- let queuer = MockTaskQueuer ( )
49
+ let queuer = MockTaskQueuer { _ in
50
+ scheduledRequestCanceled. fulfill ( )
51
+ }
47
52
transaction. requestWasQueued ( queuer)
48
53
54
+ XCTAssertEqual ( queuer. hitCancelCount, 0 )
49
55
Task . detached {
50
56
try await Task . sleep ( nanoseconds: 5 * 1000 * 1000 )
51
57
transaction. cancel ( )
52
58
}
53
59
54
- XCTAssertEqual ( queuer. hitCancelCount, 0 )
55
60
await XCTAssertThrowsError ( try await responseTask. value) { error in
56
61
XCTAssertTrue ( error is CancellationError , " unexpected error \( error) " )
57
62
}
58
- XCTAssertEqual ( queuer. hitCancelCount, 1 )
63
+
64
+ // self.fulfillment(of:) is not available on Linux
65
+ _ = {
66
+ self . wait ( for: [ scheduledRequestCanceled] , timeout: 1 )
67
+ } ( )
59
68
}
60
69
}
61
70
0 commit comments