Skip to content

Commit

Permalink
Fix availability guards and compiler warnings
Browse files Browse the repository at this point in the history
# 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
  • Loading branch information
FranzBusch committed Nov 24, 2023
1 parent ebf8b9c commit cc66436
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let package = Package(
.library(name: "NIOTransportServices", targets: ["NIOTransportServices"]),
],
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-docc-plugin", from: "1.0.0"),
],
Expand Down
130 changes: 85 additions & 45 deletions Tests/NIOTransportServicesTests/NIOTSAsyncBootstrapTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ private final class AddressedEnvelopingHandler: ChannelDuplexHandler {
}
}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
final class AsyncChannelBootstrapTests: XCTestCase {
enum NegotiationResult {
case string(NIOAsyncChannel<String, String>)
Expand Down Expand Up @@ -191,7 +192,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
try channel.pipeline.syncOperations.addHandler(MessageToByteHandler(LineDelimiterCoder()))
try channel.pipeline.syncOperations.addHandler(ByteBufferToStringHandler())
return try NIOAsyncChannel(
synchronouslyWrapping: channel,
wrappingChannelSynchronously: channel,
configuration: .init(
inboundType: String.self,
outboundType: String.self
Expand All @@ -206,16 +207,22 @@ final class AsyncChannelBootstrapTests: XCTestCase {

group.addTask {
try await withThrowingTaskGroup(of: Void.self) { _ in
for try await childChannel in channel.inbound {
for try await value in childChannel.inbound {
continuation.yield(.string(value))
try await channel.executeThenClose { inbound in
for try await childChannel in inbound {
try await childChannel.executeThenClose { childChannelInbound, _ in
for try await value in childChannelInbound {
continuation.yield(.string(value))
}
}
}
}
}
}

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"))

Expand Down Expand Up @@ -247,16 +254,22 @@ final class AsyncChannelBootstrapTests: XCTestCase {

group.addTask {
try await withThrowingTaskGroup(of: Void.self) { group in
for try await negotiationResult in channel.inbound {
group.addTask {
switch try await negotiationResult.get() {
case .string(let channel):
for try await value in channel.inbound {
continuation.yield(.string(value))
}
case .byte(let channel):
for try await value in channel.inbound {
continuation.yield(.byte(value))
try await channel.executeThenClose { inbound in
for try await negotiationResult in inbound {
group.addTask {
switch try await negotiationResult.get() {
case .string(let channel):
try await channel.executeThenClose { inbound, _ in
for try await value in inbound {
continuation.yield(.string(value))
}
}
case .byte(let channel):
try await channel.executeThenClose { inbound, _ in
for try await value in inbound {
continuation.yield(.byte(value))
}
}
}
}
}
Expand All @@ -272,7 +285,9 @@ final class AsyncChannelBootstrapTests: XCTestCase {
switch try await stringNegotiationResult.get() {
case .string(let stringChannel):
// 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"))
case .byte:
preconditionFailure()
Expand All @@ -288,7 +303,9 @@ final class AsyncChannelBootstrapTests: XCTestCase {
preconditionFailure()
case .byte(let byteChannel):
// 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))
}

Expand Down Expand Up @@ -320,16 +337,22 @@ final class AsyncChannelBootstrapTests: XCTestCase {

group.addTask {
try await withThrowingTaskGroup(of: Void.self) { group in
for try await negotiationResult in channel.inbound {
group.addTask {
switch try await negotiationResult.get().get() {
case .string(let channel):
for try await value in channel.inbound {
continuation.yield(.string(value))
}
case .byte(let channel):
for try await value in channel.inbound {
continuation.yield(.byte(value))
try await channel.executeThenClose { inbound in
for try await negotiationResult in inbound {
group.addTask {
switch try await negotiationResult.get().get() {
case .string(let channel):
try await channel.executeThenClose { inbound, _ in
for try await value in inbound {
continuation.yield(.string(value))
}
}
case .byte(let channel):
try await channel.executeThenClose { inbound, _ in
for try await value in inbound {
continuation.yield(.byte(value))
}
}
}
}
}
Expand All @@ -346,7 +369,9 @@ final class AsyncChannelBootstrapTests: XCTestCase {
switch try await stringStringNegotiationResult.get().get() {
case .string(let stringChannel):
// 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"))
case .byte:
preconditionFailure()
Expand All @@ -361,7 +386,9 @@ final class AsyncChannelBootstrapTests: XCTestCase {
switch try await byteStringNegotiationResult.get().get() {
case .string(let stringChannel):
// 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"))
case .byte:
preconditionFailure()
Expand All @@ -378,7 +405,9 @@ final class AsyncChannelBootstrapTests: XCTestCase {
preconditionFailure()
case .byte(let byteChannel):
// 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))
}

Expand All @@ -393,7 +422,9 @@ final class AsyncChannelBootstrapTests: XCTestCase {
preconditionFailure()
case .byte(let byteChannel):
// 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))
}

Expand Down Expand Up @@ -448,16 +479,22 @@ final class AsyncChannelBootstrapTests: XCTestCase {

group.addTask {
try await withThrowingTaskGroup(of: Void.self) { group in
for try await negotiationResult in channel.inbound {
group.addTask {
switch try await negotiationResult.get() {
case .string(let channel):
for try await value in channel.inbound {
continuation.yield(.string(value))
}
case .byte(let channel):
for try await value in channel.inbound {
continuation.yield(.byte(value))
try await channel.executeThenClose { inbound in
for try await negotiationResult in inbound {
group.addTask {
switch try await negotiationResult.get() {
case .string(let channel):
try await channel.executeThenClose { inbound, _ in
for try await value in inbound {
continuation.yield(.string(value))
}
}
case .byte(let channel):
try await channel.executeThenClose { inbound, _ in
for try await value in inbound {
continuation.yield(.byte(value))
}
}
}
}
}
Expand All @@ -483,7 +520,9 @@ final class AsyncChannelBootstrapTests: XCTestCase {
switch try await stringNegotiationResult.get() {
case .string(let stringChannel):
// 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"))
case .byte:
preconditionFailure()
Expand Down Expand Up @@ -514,7 +553,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
try channel.pipeline.syncOperations.addHandler(MessageToByteHandler(LineDelimiterCoder()))
try channel.pipeline.syncOperations.addHandler(ByteBufferToStringHandler())
return try NIOAsyncChannel(
synchronouslyWrapping: channel,
wrappingChannelSynchronously: channel,
configuration: .init(
inboundType: String.self,
outboundType: String.self
Expand Down Expand Up @@ -618,7 +657,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
return channel.eventLoop.makeCompletedFuture {
try channel.pipeline.syncOperations.addHandler(ByteBufferToStringHandler())
let asyncChannel: NIOAsyncChannel<String, String> = try NIOAsyncChannel(
synchronouslyWrapping: channel
wrappingChannelSynchronously: channel
)

return NegotiationResult.string(asyncChannel)
Expand All @@ -628,7 +667,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
try channel.pipeline.syncOperations.addHandler(ByteBufferToByteHandler())

let asyncChannel: NIOAsyncChannel<UInt8, UInt8> = try NIOAsyncChannel(
synchronouslyWrapping: channel
wrappingChannelSynchronously: channel
)

return NegotiationResult.byte(asyncChannel)
Expand All @@ -646,6 +685,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
}
}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension AsyncStream {
fileprivate static func makeStream(
of elementType: Element.Type = Element.self,
Expand Down
2 changes: 2 additions & 0 deletions Tests/NIOTransportServicesTests/NIOTSEventLoopTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,12 @@ class NIOTSEventLoopTest: XCTestCase {
XCTAssertNil(weakEL)
}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
func testGroupCanBeShutDown() async throws {
try await NIOTSEventLoopGroup(loopCount: 3).shutdownGracefully()
}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
func testIndividualLoopsCannotBeShutDownWhenPartOfGroup() async throws {
let group = NIOTSEventLoopGroup(loopCount: 3)
defer {
Expand Down
1 change: 1 addition & 0 deletions Tests/NIOTransportServicesTests/NIOTSSingletonTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import XCTest
import NIOTransportServices
import NIOCore

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
final class NIOSingletonsTests: XCTestCase {
func testNIOSingletonsTransportServicesEventLoopGroupWorks() async throws {
let works = try await NIOSingletons.transportServicesEventLoopGroup.any().submit { "yes" }.get()
Expand Down

0 comments on commit cc66436

Please sign in to comment.