Fix availability guards and compiler warnings (#193)
# Motivation We missed a few availability guards in our tests which caused errors when compiling for older Darwin platforms. Additionally the latest NIO release deprecated a few APIs on `NIOAsyncChannel`. # Modification This PR adds the missing guards and fixes all of the deprecation warnings. # Result We should build on all supported platforms again
This commit is contained in:
parent
ebf8b9c365
commit
2f6ba3d83c
|
|
@ -21,7 +21,7 @@ let package = Package(
|
||||||
.library(name: "NIOTransportServices", targets: ["NIOTransportServices"]),
|
.library(name: "NIOTransportServices", targets: ["NIOTransportServices"]),
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.package(url: "https://github.com/apple/swift-nio.git", from: "2.60.0"),
|
.package(url: "https://github.com/apple/swift-nio.git", from: "2.62.0"),
|
||||||
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.0.2"),
|
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.0.2"),
|
||||||
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
|
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -160,6 +160,7 @@ private final class AddressedEnvelopingHandler: ChannelDuplexHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||||
final class AsyncChannelBootstrapTests: XCTestCase {
|
final class AsyncChannelBootstrapTests: XCTestCase {
|
||||||
enum NegotiationResult {
|
enum NegotiationResult {
|
||||||
case string(NIOAsyncChannel<String, String>)
|
case string(NIOAsyncChannel<String, String>)
|
||||||
|
|
@ -191,7 +192,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
|
||||||
try channel.pipeline.syncOperations.addHandler(MessageToByteHandler(LineDelimiterCoder()))
|
try channel.pipeline.syncOperations.addHandler(MessageToByteHandler(LineDelimiterCoder()))
|
||||||
try channel.pipeline.syncOperations.addHandler(ByteBufferToStringHandler())
|
try channel.pipeline.syncOperations.addHandler(ByteBufferToStringHandler())
|
||||||
return try NIOAsyncChannel(
|
return try NIOAsyncChannel(
|
||||||
synchronouslyWrapping: channel,
|
wrappingChannelSynchronously: channel,
|
||||||
configuration: .init(
|
configuration: .init(
|
||||||
inboundType: String.self,
|
inboundType: String.self,
|
||||||
outboundType: String.self
|
outboundType: String.self
|
||||||
|
|
@ -206,16 +207,22 @@ final class AsyncChannelBootstrapTests: XCTestCase {
|
||||||
|
|
||||||
group.addTask {
|
group.addTask {
|
||||||
try await withThrowingTaskGroup(of: Void.self) { _ in
|
try await withThrowingTaskGroup(of: Void.self) { _ in
|
||||||
for try await childChannel in channel.inbound {
|
try await channel.executeThenClose { inbound in
|
||||||
for try await value in childChannel.inbound {
|
for try await childChannel in inbound {
|
||||||
|
try await childChannel.executeThenClose { childChannelInbound, _ in
|
||||||
|
for try await value in childChannelInbound {
|
||||||
continuation.yield(.string(value))
|
continuation.yield(.string(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let stringChannel = try await self.makeClientChannel(eventLoopGroup: eventLoopGroup, port: channel.channel.localAddress!.port!)
|
let stringChannel = try await self.makeClientChannel(eventLoopGroup: eventLoopGroup, port: channel.channel.localAddress!.port!)
|
||||||
try await stringChannel.outbound.write("hello")
|
try await stringChannel.executeThenClose { _, outbound in
|
||||||
|
try await outbound.write("hello")
|
||||||
|
}
|
||||||
|
|
||||||
await XCTAsyncAssertEqual(await iterator.next(), .string("hello"))
|
await XCTAsyncAssertEqual(await iterator.next(), .string("hello"))
|
||||||
|
|
||||||
|
|
@ -247,15 +254,19 @@ final class AsyncChannelBootstrapTests: XCTestCase {
|
||||||
|
|
||||||
group.addTask {
|
group.addTask {
|
||||||
try await withThrowingTaskGroup(of: Void.self) { group in
|
try await withThrowingTaskGroup(of: Void.self) { group in
|
||||||
for try await negotiationResult in channel.inbound {
|
try await channel.executeThenClose { inbound in
|
||||||
|
for try await negotiationResult in inbound {
|
||||||
group.addTask {
|
group.addTask {
|
||||||
switch try await negotiationResult.get() {
|
switch try await negotiationResult.get() {
|
||||||
case .string(let channel):
|
case .string(let channel):
|
||||||
for try await value in channel.inbound {
|
try await channel.executeThenClose { inbound, _ in
|
||||||
|
for try await value in inbound {
|
||||||
continuation.yield(.string(value))
|
continuation.yield(.string(value))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
case .byte(let channel):
|
case .byte(let channel):
|
||||||
for try await value in channel.inbound {
|
try await channel.executeThenClose { inbound, _ in
|
||||||
|
for try await value in inbound {
|
||||||
continuation.yield(.byte(value))
|
continuation.yield(.byte(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -263,6 +274,8 @@ final class AsyncChannelBootstrapTests: XCTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let stringNegotiationResult = try await self.makeClientChannelWithProtocolNegotiation(
|
let stringNegotiationResult = try await self.makeClientChannelWithProtocolNegotiation(
|
||||||
eventLoopGroup: eventLoopGroup,
|
eventLoopGroup: eventLoopGroup,
|
||||||
|
|
@ -272,7 +285,9 @@ final class AsyncChannelBootstrapTests: XCTestCase {
|
||||||
switch try await stringNegotiationResult.get() {
|
switch try await stringNegotiationResult.get() {
|
||||||
case .string(let stringChannel):
|
case .string(let stringChannel):
|
||||||
// This is the actual content
|
// This is the actual content
|
||||||
try await stringChannel.outbound.write("hello")
|
try await stringChannel.executeThenClose { _, outbound in
|
||||||
|
try await outbound.write("hello")
|
||||||
|
}
|
||||||
await XCTAsyncAssertEqual(await serverIterator.next(), .string("hello"))
|
await XCTAsyncAssertEqual(await serverIterator.next(), .string("hello"))
|
||||||
case .byte:
|
case .byte:
|
||||||
preconditionFailure()
|
preconditionFailure()
|
||||||
|
|
@ -288,7 +303,9 @@ final class AsyncChannelBootstrapTests: XCTestCase {
|
||||||
preconditionFailure()
|
preconditionFailure()
|
||||||
case .byte(let byteChannel):
|
case .byte(let byteChannel):
|
||||||
// This is the actual content
|
// This is the actual content
|
||||||
try await byteChannel.outbound.write(UInt8(8))
|
try await byteChannel.executeThenClose { _, outbound in
|
||||||
|
try await outbound.write(UInt8(8))
|
||||||
|
}
|
||||||
await XCTAsyncAssertEqual(await serverIterator.next(), .byte(8))
|
await XCTAsyncAssertEqual(await serverIterator.next(), .byte(8))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -320,15 +337,19 @@ final class AsyncChannelBootstrapTests: XCTestCase {
|
||||||
|
|
||||||
group.addTask {
|
group.addTask {
|
||||||
try await withThrowingTaskGroup(of: Void.self) { group in
|
try await withThrowingTaskGroup(of: Void.self) { group in
|
||||||
for try await negotiationResult in channel.inbound {
|
try await channel.executeThenClose { inbound in
|
||||||
|
for try await negotiationResult in inbound {
|
||||||
group.addTask {
|
group.addTask {
|
||||||
switch try await negotiationResult.get().get() {
|
switch try await negotiationResult.get().get() {
|
||||||
case .string(let channel):
|
case .string(let channel):
|
||||||
for try await value in channel.inbound {
|
try await channel.executeThenClose { inbound, _ in
|
||||||
|
for try await value in inbound {
|
||||||
continuation.yield(.string(value))
|
continuation.yield(.string(value))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
case .byte(let channel):
|
case .byte(let channel):
|
||||||
for try await value in channel.inbound {
|
try await channel.executeThenClose { inbound, _ in
|
||||||
|
for try await value in inbound {
|
||||||
continuation.yield(.byte(value))
|
continuation.yield(.byte(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -336,6 +357,8 @@ final class AsyncChannelBootstrapTests: XCTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let stringStringNegotiationResult = try await self.makeClientChannelWithNestedProtocolNegotiation(
|
let stringStringNegotiationResult = try await self.makeClientChannelWithNestedProtocolNegotiation(
|
||||||
eventLoopGroup: eventLoopGroup,
|
eventLoopGroup: eventLoopGroup,
|
||||||
|
|
@ -346,7 +369,9 @@ final class AsyncChannelBootstrapTests: XCTestCase {
|
||||||
switch try await stringStringNegotiationResult.get().get() {
|
switch try await stringStringNegotiationResult.get().get() {
|
||||||
case .string(let stringChannel):
|
case .string(let stringChannel):
|
||||||
// This is the actual content
|
// This is the actual content
|
||||||
try await stringChannel.outbound.write("hello")
|
try await stringChannel.executeThenClose { _, outbound in
|
||||||
|
try await outbound.write("hello")
|
||||||
|
}
|
||||||
await XCTAsyncAssertEqual(await serverIterator.next(), .string("hello"))
|
await XCTAsyncAssertEqual(await serverIterator.next(), .string("hello"))
|
||||||
case .byte:
|
case .byte:
|
||||||
preconditionFailure()
|
preconditionFailure()
|
||||||
|
|
@ -361,7 +386,9 @@ final class AsyncChannelBootstrapTests: XCTestCase {
|
||||||
switch try await byteStringNegotiationResult.get().get() {
|
switch try await byteStringNegotiationResult.get().get() {
|
||||||
case .string(let stringChannel):
|
case .string(let stringChannel):
|
||||||
// This is the actual content
|
// This is the actual content
|
||||||
try await stringChannel.outbound.write("hello")
|
try await stringChannel.executeThenClose { _, outbound in
|
||||||
|
try await outbound.write("hello")
|
||||||
|
}
|
||||||
await XCTAsyncAssertEqual(await serverIterator.next(), .string("hello"))
|
await XCTAsyncAssertEqual(await serverIterator.next(), .string("hello"))
|
||||||
case .byte:
|
case .byte:
|
||||||
preconditionFailure()
|
preconditionFailure()
|
||||||
|
|
@ -378,7 +405,9 @@ final class AsyncChannelBootstrapTests: XCTestCase {
|
||||||
preconditionFailure()
|
preconditionFailure()
|
||||||
case .byte(let byteChannel):
|
case .byte(let byteChannel):
|
||||||
// This is the actual content
|
// This is the actual content
|
||||||
try await byteChannel.outbound.write(UInt8(8))
|
try await byteChannel.executeThenClose { _, outbound in
|
||||||
|
try await outbound.write(UInt8(8))
|
||||||
|
}
|
||||||
await XCTAsyncAssertEqual(await serverIterator.next(), .byte(8))
|
await XCTAsyncAssertEqual(await serverIterator.next(), .byte(8))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -393,7 +422,9 @@ final class AsyncChannelBootstrapTests: XCTestCase {
|
||||||
preconditionFailure()
|
preconditionFailure()
|
||||||
case .byte(let byteChannel):
|
case .byte(let byteChannel):
|
||||||
// This is the actual content
|
// This is the actual content
|
||||||
try await byteChannel.outbound.write(UInt8(8))
|
try await byteChannel.executeThenClose { _, outbound in
|
||||||
|
try await outbound.write(UInt8(8))
|
||||||
|
}
|
||||||
await XCTAsyncAssertEqual(await serverIterator.next(), .byte(8))
|
await XCTAsyncAssertEqual(await serverIterator.next(), .byte(8))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -448,15 +479,19 @@ final class AsyncChannelBootstrapTests: XCTestCase {
|
||||||
|
|
||||||
group.addTask {
|
group.addTask {
|
||||||
try await withThrowingTaskGroup(of: Void.self) { group in
|
try await withThrowingTaskGroup(of: Void.self) { group in
|
||||||
for try await negotiationResult in channel.inbound {
|
try await channel.executeThenClose { inbound in
|
||||||
|
for try await negotiationResult in inbound {
|
||||||
group.addTask {
|
group.addTask {
|
||||||
switch try await negotiationResult.get() {
|
switch try await negotiationResult.get() {
|
||||||
case .string(let channel):
|
case .string(let channel):
|
||||||
for try await value in channel.inbound {
|
try await channel.executeThenClose { inbound, _ in
|
||||||
|
for try await value in inbound {
|
||||||
continuation.yield(.string(value))
|
continuation.yield(.string(value))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
case .byte(let channel):
|
case .byte(let channel):
|
||||||
for try await value in channel.inbound {
|
try await channel.executeThenClose { inbound, _ in
|
||||||
|
for try await value in inbound {
|
||||||
continuation.yield(.byte(value))
|
continuation.yield(.byte(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -464,6 +499,8 @@ final class AsyncChannelBootstrapTests: XCTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let failedProtocolNegotiation = try await self.makeClientChannelWithProtocolNegotiation(
|
let failedProtocolNegotiation = try await self.makeClientChannelWithProtocolNegotiation(
|
||||||
eventLoopGroup: eventLoopGroup,
|
eventLoopGroup: eventLoopGroup,
|
||||||
|
|
@ -483,7 +520,9 @@ final class AsyncChannelBootstrapTests: XCTestCase {
|
||||||
switch try await stringNegotiationResult.get() {
|
switch try await stringNegotiationResult.get() {
|
||||||
case .string(let stringChannel):
|
case .string(let stringChannel):
|
||||||
// This is the actual content
|
// This is the actual content
|
||||||
try await stringChannel.outbound.write("hello")
|
try await stringChannel.executeThenClose { _, outbound in
|
||||||
|
try await outbound.write("hello")
|
||||||
|
}
|
||||||
await XCTAsyncAssertEqual(await serverIterator.next(), .string("hello"))
|
await XCTAsyncAssertEqual(await serverIterator.next(), .string("hello"))
|
||||||
case .byte:
|
case .byte:
|
||||||
preconditionFailure()
|
preconditionFailure()
|
||||||
|
|
@ -514,7 +553,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
|
||||||
try channel.pipeline.syncOperations.addHandler(MessageToByteHandler(LineDelimiterCoder()))
|
try channel.pipeline.syncOperations.addHandler(MessageToByteHandler(LineDelimiterCoder()))
|
||||||
try channel.pipeline.syncOperations.addHandler(ByteBufferToStringHandler())
|
try channel.pipeline.syncOperations.addHandler(ByteBufferToStringHandler())
|
||||||
return try NIOAsyncChannel(
|
return try NIOAsyncChannel(
|
||||||
synchronouslyWrapping: channel,
|
wrappingChannelSynchronously: channel,
|
||||||
configuration: .init(
|
configuration: .init(
|
||||||
inboundType: String.self,
|
inboundType: String.self,
|
||||||
outboundType: String.self
|
outboundType: String.self
|
||||||
|
|
@ -618,7 +657,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
|
||||||
return channel.eventLoop.makeCompletedFuture {
|
return channel.eventLoop.makeCompletedFuture {
|
||||||
try channel.pipeline.syncOperations.addHandler(ByteBufferToStringHandler())
|
try channel.pipeline.syncOperations.addHandler(ByteBufferToStringHandler())
|
||||||
let asyncChannel: NIOAsyncChannel<String, String> = try NIOAsyncChannel(
|
let asyncChannel: NIOAsyncChannel<String, String> = try NIOAsyncChannel(
|
||||||
synchronouslyWrapping: channel
|
wrappingChannelSynchronously: channel
|
||||||
)
|
)
|
||||||
|
|
||||||
return NegotiationResult.string(asyncChannel)
|
return NegotiationResult.string(asyncChannel)
|
||||||
|
|
@ -628,7 +667,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
|
||||||
try channel.pipeline.syncOperations.addHandler(ByteBufferToByteHandler())
|
try channel.pipeline.syncOperations.addHandler(ByteBufferToByteHandler())
|
||||||
|
|
||||||
let asyncChannel: NIOAsyncChannel<UInt8, UInt8> = try NIOAsyncChannel(
|
let asyncChannel: NIOAsyncChannel<UInt8, UInt8> = try NIOAsyncChannel(
|
||||||
synchronouslyWrapping: channel
|
wrappingChannelSynchronously: channel
|
||||||
)
|
)
|
||||||
|
|
||||||
return NegotiationResult.byte(asyncChannel)
|
return NegotiationResult.byte(asyncChannel)
|
||||||
|
|
@ -646,6 +685,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||||
extension AsyncStream {
|
extension AsyncStream {
|
||||||
fileprivate static func makeStream(
|
fileprivate static func makeStream(
|
||||||
of elementType: Element.Type = Element.self,
|
of elementType: Element.Type = Element.self,
|
||||||
|
|
|
||||||
|
|
@ -130,10 +130,12 @@ class NIOTSEventLoopTest: XCTestCase {
|
||||||
XCTAssertNil(weakEL)
|
XCTAssertNil(weakEL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||||
func testGroupCanBeShutDown() async throws {
|
func testGroupCanBeShutDown() async throws {
|
||||||
try await NIOTSEventLoopGroup(loopCount: 3).shutdownGracefully()
|
try await NIOTSEventLoopGroup(loopCount: 3).shutdownGracefully()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||||
func testIndividualLoopsCannotBeShutDownWhenPartOfGroup() async throws {
|
func testIndividualLoopsCannotBeShutDownWhenPartOfGroup() async throws {
|
||||||
let group = NIOTSEventLoopGroup(loopCount: 3)
|
let group = NIOTSEventLoopGroup(loopCount: 3)
|
||||||
defer {
|
defer {
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ import XCTest
|
||||||
import NIOTransportServices
|
import NIOTransportServices
|
||||||
import NIOCore
|
import NIOCore
|
||||||
|
|
||||||
|
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||||
final class NIOSingletonsTests: XCTestCase {
|
final class NIOSingletonsTests: XCTestCase {
|
||||||
func testNIOSingletonsTransportServicesEventLoopGroupWorks() async throws {
|
func testNIOSingletonsTransportServicesEventLoopGroupWorks() async throws {
|
||||||
let works = try await NIOSingletons.transportServicesEventLoopGroup.any().submit { "yes" }.get()
|
let works = try await NIOSingletons.transportServicesEventLoopGroup.any().submit { "yes" }.get()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue