Skip to content

Commit

Permalink
Use APIs available on older macOS in tests (#25)
Browse files Browse the repository at this point in the history
### 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.
  • Loading branch information
simonjbeaumont authored Nov 17, 2023
1 parent 686df72 commit 8464a53
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ class HTTPBodyOutputStreamBridgeTests: XCTestCase {
XCTAssertNil(inputStream.streamError)

// Check the output stream closes gracefully in response to the input stream closing.
HTTPBodyOutputStreamBridge.streamQueue.asyncAndWait {
XCTAssertEqual(requestStream.outputStream.streamStatus, .closed)
XCTAssertNil(requestStream.outputStream.streamError)
}
HTTPBodyOutputStreamBridge.streamQueue.asyncAndWait(
execute: DispatchWorkItem {
XCTAssertEqual(requestStream.outputStream.streamStatus, .closed)
XCTAssertNil(requestStream.outputStream.streamError)
}
)
}

func testHTTPBodyOutputStreamBridgeBackpressure() async throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class URLSessionBidirectionalStreamingTests: XCTestCase {
// Just count the bytes received and verify the total matches what the server sent.
case count
// Add some artificial delay to simulate business logic to show how the backpressure mechanism works (or not).
case delay(Duration)
case delay(TimeAmount)
}

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

Expand Down

0 comments on commit 8464a53

Please sign in to comment.