Skip to content

Commit

Permalink
Add missing availability guards in tests (#429)
Browse files Browse the repository at this point in the history
## Motivation

Some of the test code was missing availability guards for Apple platforms, resulting in build failures for these platforms, e.g.

```
error: 'NIOAsyncTestingChannel' is only available in iOS 13.0 or newer
         var clientChannel: NIOAsyncTestingChannel!
```

## Modifications

Add missing availability guards. I've tried to keep them as scoped as possible. Some test suites used these as class properties, so these got a guard at suite level.

## Result

Tests can now build and run on iOS and other Apple platforms.
  • Loading branch information
simonjbeaumont authored Dec 15, 2023
1 parent 285e444 commit 28a91a3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import NIOHTTP1
import NIOHTTP2
import NIOTLS

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
final class ConfiguringPipelineAsyncMultiplexerTests: XCTestCase {
var clientChannel: NIOAsyncTestingChannel!
var serverChannel: NIOAsyncTestingChannel!
Expand Down Expand Up @@ -150,6 +151,7 @@ final class ConfiguringPipelineAsyncMultiplexerTests: XCTestCase {

// `testNIOAsyncConnectionStreamChannelPipelineCommunicates` ensures that a client-server system set up to use `NIOAsyncChannel`
// wrappers around connection and stream channels can communicate successfully.
@available(*, deprecated, message: "Deprecated so deprecated functionality can be tested without warnings")
func testNIOAsyncConnectionStreamChannelPipelineCommunicates() async throws {
let requestCount = 100

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ final class HTTP2FramePayloadStreamMultiplexerTests: XCTestCase {
XCTAssertNoThrow(try self.channel.finish())
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
func testFlushingOneChannelDoesntFlushThemAll() async throws {
let writeTracker = FrameWriteRecorder()
let (channelsStream, channelsContinuation) = AsyncStream.makeStream(of: Channel.self)
Expand Down Expand Up @@ -801,6 +802,7 @@ final class HTTP2FramePayloadStreamMultiplexerTests: XCTestCase {
XCTAssertNoThrow(try self.channel.finish())
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
func testReadIsPerChannel() async throws {
let firstStreamID = HTTP2StreamID(1)
let secondStreamID = HTTP2StreamID(3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ final class HTTP2InlineStreamMultiplexerTests: XCTestCase {
XCTAssertNoThrow(try self.channel.finish())
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
func testFlushingOneChannelDoesntFlushThemAll() async throws {
let writeTracker = IODataWriteRecorder()
let (channelsStream, channelsContinuation) = AsyncStream.makeStream(of: Channel.self)
Expand Down
2 changes: 2 additions & 0 deletions Tests/NIOHTTP2Tests/HTTP2StreamMultiplexerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ final class HTTP2StreamMultiplexerTests: XCTestCase {
}

@available(*, deprecated, message: "Deprecated so deprecated functionality can be tested without warnings")
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
func testFlushingOneChannelDoesntFlushThemAll() async throws {
let writeTracker = FrameWriteRecorder()

Expand Down Expand Up @@ -998,6 +999,7 @@ final class HTTP2StreamMultiplexerTests: XCTestCase {
}

@available(*, deprecated, message: "Deprecated so deprecated functionality can be tested without warnings")
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
func testReadIsPerChannel() async throws {
let firstStreamID = HTTP2StreamID(1)
let secondStreamID = HTTP2StreamID(3)
Expand Down
6 changes: 6 additions & 0 deletions Tests/NIOHTTP2Tests/TestUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ extension XCTestCase {
/// they make no forward progress.
///
/// ** This function is racy and can lead to deadlocks, prefer the one-way variant which is less error-prone**
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
func interactInMemory(_ first: NIOAsyncTestingChannel, _ second: NIOAsyncTestingChannel, file: StaticString = #filePath, line: UInt = #line) async throws {
var operated: Bool

Expand All @@ -88,6 +89,7 @@ extension XCTestCase {
}

/// Have a `NIOAsyncTestingChannel` send data to another until it makes no forward progress.
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
static func deliverAllBytes(from source: NIOAsyncTestingChannel, to destination: NIOAsyncTestingChannel, file: StaticString = #filePath, line: UInt = #line) async throws {
var operated: Bool

Expand Down Expand Up @@ -157,6 +159,7 @@ extension XCTestCase {
///
/// If the handshake has not occurred, this will definitely call `XCTFail`. It may also throw if the
/// channel is now in an indeterminate state.
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
func assertDoHandshake(client: NIOAsyncTestingChannel, server: NIOAsyncTestingChannel,
clientSettings: [HTTP2Setting] = nioDefaultSettings, serverSettings: [HTTP2Setting] = nioDefaultSettings,
file: StaticString = #filePath, line: UInt = #line) async throws {
Expand Down Expand Up @@ -272,6 +275,7 @@ extension EmbeddedChannel {
}
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
extension NIOAsyncTestingChannel {
/// This function attempts to obtain a HTTP/2 frame from a connection. It must already have been
/// sent, as this function does not call `interactInMemory`. If no frame has been received, this
Expand Down Expand Up @@ -896,6 +900,7 @@ func assertNoThrowWithValue<T>(
}
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
func assertNoThrowWithValue<T>(
_ body: @autoclosure () async throws -> T,
defaultValue: T? = nil,
Expand All @@ -915,6 +920,7 @@ func assertNoThrowWithValue<T>(
}
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
func assertNoThrow<T>(
_ body: @autoclosure () async throws -> T,
defaultValue: T? = nil,
Expand Down

0 comments on commit 28a91a3

Please sign in to comment.