Skip to content

Commit 8464a53

Browse files
Use APIs available on older macOS in tests (#25)
### Motivation The tests fail to compile on anything older than macOS 13, because they use a number of APIs only available in macOS 13+: - `Duration` - `Task.sleep(for:)` - `DispatchQueue.asyncAndWait` (closure variant) ### Modifications Use the following APIs instead: - `NIO.TimeInterval` (we have NIO dependency in tests already). - `Task.sleep(nanoseconds:)` - `DispatchQueue.asyncAndWait(execute:)` ### Result Tests can be built on older platforms.
1 parent 686df72 commit 8464a53

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

Tests/OpenAPIURLSessionTests/URLSessionBidirectionalStreamingTests/HTTPBodyOutputStreamTests.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ class HTTPBodyOutputStreamBridgeTests: XCTestCase {
6060
XCTAssertNil(inputStream.streamError)
6161

6262
// Check the output stream closes gracefully in response to the input stream closing.
63-
HTTPBodyOutputStreamBridge.streamQueue.asyncAndWait {
64-
XCTAssertEqual(requestStream.outputStream.streamStatus, .closed)
65-
XCTAssertNil(requestStream.outputStream.streamError)
66-
}
63+
HTTPBodyOutputStreamBridge.streamQueue.asyncAndWait(
64+
execute: DispatchWorkItem {
65+
XCTAssertEqual(requestStream.outputStream.streamStatus, .closed)
66+
XCTAssertNil(requestStream.outputStream.streamError)
67+
}
68+
)
6769
}
6870

6971
func testHTTPBodyOutputStreamBridgeBackpressure() async throws {

Tests/OpenAPIURLSessionTests/URLSessionBidirectionalStreamingTests/URLSessionBidirectionalStreamingTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ class URLSessionBidirectionalStreamingTests: XCTestCase {
305305
// Just count the bytes received and verify the total matches what the server sent.
306306
case count
307307
// Add some artificial delay to simulate business logic to show how the backpressure mechanism works (or not).
308-
case delay(Duration)
308+
case delay(TimeAmount)
309309
}
310310

311311
func testStreamingDownload(
@@ -387,7 +387,7 @@ class URLSessionBidirectionalStreamingTests: XCTestCase {
387387
for try await receivedResponseChunk in responseBody! {
388388
print("Client received some response body bytes (numBytes: \(receivedResponseChunk.count))")
389389
print("Client doing fake work for \(delay)s")
390-
try await Task.sleep(for: delay)
390+
try await Task.sleep(nanoseconds: UInt64(delay.nanoseconds))
391391
}
392392
}
393393

0 commit comments

Comments
 (0)