diff --git a/Package.swift b/Package.swift index 72ffc7e5..f2355d6e 100644 --- a/Package.swift +++ b/Package.swift @@ -211,7 +211,7 @@ let package = Package( .library(name: "NIOResumableUpload", targets: ["NIOResumableUpload"]), ], dependencies: [ - .package(url: "https://github.com/apple/swift-nio.git", from: "2.67.0"), + .package(url: "https://github.com/apple/swift-nio.git", from: "2.78.0"), .package(url: "https://github.com/apple/swift-nio-http2.git", from: "1.27.0"), .package(url: "https://github.com/apple/swift-http-types.git", from: "1.3.0"), .package(url: "https://github.com/apple/swift-http-structured-headers.git", from: "1.1.0"), diff --git a/Sources/NIOExtras/HTTP1ProxyConnectHandler.swift b/Sources/NIOExtras/HTTP1ProxyConnectHandler.swift index eb9dc2fd..a099f698 100644 --- a/Sources/NIOExtras/HTTP1ProxyConnectHandler.swift +++ b/Sources/NIOExtras/HTTP1ProxyConnectHandler.swift @@ -241,7 +241,7 @@ public final class NIOHTTP1ProxyConnectHandler: ChannelDuplexHandler, RemovableC } // Ok, we've set up the proxy connection. We can now remove ourselves, which should happen synchronously. - context.pipeline.removeHandler(context: context, promise: nil) + context.pipeline.syncOperations.removeHandler(context: context, promise: nil) self.promise?.succeed(()) } diff --git a/Sources/NIOExtras/WritePCAPHandler.swift b/Sources/NIOExtras/WritePCAPHandler.swift index cab5a649..2e3f11ad 100644 --- a/Sources/NIOExtras/WritePCAPHandler.swift +++ b/Sources/NIOExtras/WritePCAPHandler.swift @@ -738,7 +738,7 @@ extension NIOWritePCAPHandler { } } return SynchronizedFileSink( - fileHandle: NIOFileHandle(descriptor: fd), + fileHandle: NIOFileHandle(_deprecatedTakingOwnershipOfDescriptor: fd), errorHandler: errorHandler ) } diff --git a/Sources/NIOExtrasPerformanceTester/HTTP1PCAPPerformanceTests.swift b/Sources/NIOExtrasPerformanceTester/HTTP1PCAPPerformanceTests.swift index c8f3ffbe..2a353726 100644 --- a/Sources/NIOExtrasPerformanceTester/HTTP1PCAPPerformanceTests.swift +++ b/Sources/NIOExtrasPerformanceTester/HTTP1PCAPPerformanceTests.swift @@ -37,11 +37,13 @@ class HTTP1ThreadedPCapPerformanceTest: HTTP1ThreadedPerformanceTest { init() { let sinkHolder = SinkHolder() func addPCap(channel: Channel) -> EventLoopFuture { - let pcapHandler = NIOWritePCAPHandler( - mode: .client, - fileSink: sinkHolder.fileSink.write - ) - return channel.pipeline.addHandler(pcapHandler, position: .first) + channel.eventLoop.submit { + let pcapHandler = NIOWritePCAPHandler( + mode: .client, + fileSink: sinkHolder.fileSink.write + ) + return try channel.pipeline.syncOperations.addHandler(pcapHandler, position: .first) + } } self.sinkHolder = sinkHolder diff --git a/Sources/NIOExtrasPerformanceTester/HTTP1PerformanceTestFramework.swift b/Sources/NIOExtrasPerformanceTester/HTTP1PerformanceTestFramework.swift index 01bb90d4..0e9e3ac7 100644 --- a/Sources/NIOExtrasPerformanceTester/HTTP1PerformanceTestFramework.swift +++ b/Sources/NIOExtrasPerformanceTester/HTTP1PerformanceTestFramework.swift @@ -193,8 +193,8 @@ class HTTP1ThreadedPerformanceTest: Benchmark { var writeFutures: [EventLoopFuture] = [] for clientChannel in clientChannels { - clientChannel.write(NIOAny(HTTPClientRequestPart.head(self.head)), promise: nil) - writeFutures.append(clientChannel.writeAndFlush(NIOAny(HTTPClientRequestPart.end(nil)))) + clientChannel.write(HTTPClientRequestPart.head(self.head), promise: nil) + writeFutures.append(clientChannel.writeAndFlush(HTTPClientRequestPart.end(nil))) } let allWrites = EventLoopFuture.andAllComplete(writeFutures, on: writeFutures.first!.eventLoop) try! allWrites.wait() diff --git a/Sources/NIOExtrasPerformanceTester/HTTP1RollingPCAPPerformanceTests.swift b/Sources/NIOExtrasPerformanceTester/HTTP1RollingPCAPPerformanceTests.swift index cc1314a5..392c0c9c 100644 --- a/Sources/NIOExtrasPerformanceTester/HTTP1RollingPCAPPerformanceTests.swift +++ b/Sources/NIOExtrasPerformanceTester/HTTP1RollingPCAPPerformanceTests.swift @@ -18,15 +18,17 @@ import NIOExtras class HTTP1ThreadedRollingPCapPerformanceTest: HTTP1ThreadedPerformanceTest { init() { func addRollingPCap(channel: Channel) -> EventLoopFuture { - let pcapRingBuffer = NIOPCAPRingBuffer( - maximumFragments: 25, - maximumBytes: 1_000_000 - ) - let pcapHandler = NIOWritePCAPHandler( - mode: .client, - fileSink: pcapRingBuffer.addFragment - ) - return channel.pipeline.addHandler(pcapHandler, position: .first) + channel.eventLoop.submit { + let pcapRingBuffer = NIOPCAPRingBuffer( + maximumFragments: 25, + maximumBytes: 1_000_000 + ) + let pcapHandler = NIOWritePCAPHandler( + mode: .client, + fileSink: pcapRingBuffer.addFragment + ) + try channel.pipeline.syncOperations.addHandler(pcapHandler, position: .first) + } } super.init( diff --git a/Sources/NIOExtrasPerformanceTester/PCAPPerformanceTest.swift b/Sources/NIOExtrasPerformanceTester/PCAPPerformanceTest.swift index c4a93b14..d02b7ff9 100644 --- a/Sources/NIOExtrasPerformanceTester/PCAPPerformanceTest.swift +++ b/Sources/NIOExtrasPerformanceTester/PCAPPerformanceTest.swift @@ -53,7 +53,7 @@ final class PCAPPerformanceTest: Benchmark { mode: .client, fileSink: fileSink.write ) - try channel.pipeline.addHandler(pcapHandler, position: .first).wait() + try channel.pipeline.syncOperations.addHandler(pcapHandler, position: .first) for _ in 0..] = [] promises.append(embedded.eventLoop.makePromise()) - embedded.pipeline.write(NIOAny(HTTPClientRequestPart.head(requestHead)), promise: promises.last) + embedded.pipeline.write(HTTPClientRequestPart.head(requestHead), promise: promises.last) promises.append(embedded.eventLoop.makePromise()) embedded.pipeline.write( - NIOAny(HTTPClientRequestPart.body(.byteBuffer(ByteBuffer(string: "Test")))), + HTTPClientRequestPart.body(.byteBuffer(ByteBuffer(string: "Test"))), promise: promises.last ) promises.append(embedded.eventLoop.makePromise()) - embedded.pipeline.write(NIOAny(HTTPClientRequestPart.end(nil)), promise: promises.last) + embedded.pipeline.write(HTTPClientRequestPart.end(nil), promise: promises.last) embedded.pipeline.flush() // read the connect header back @@ -291,16 +291,16 @@ class HTTP1ProxyConnectHandlerTests: XCTestCase { let requestHead = HTTPRequestHead(version: HTTPVersion(major: 1, minor: 1), method: .GET, uri: "apple.com") var promises: [EventLoopPromise] = [] promises.append(embedded.eventLoop.makePromise()) - embedded.pipeline.write(NIOAny(HTTPClientRequestPart.head(requestHead)), promise: promises.last) + embedded.pipeline.write(HTTPClientRequestPart.head(requestHead), promise: promises.last) promises.append(embedded.eventLoop.makePromise()) embedded.pipeline.write( - NIOAny(HTTPClientRequestPart.body(.byteBuffer(ByteBuffer(string: "Test")))), + HTTPClientRequestPart.body(.byteBuffer(ByteBuffer(string: "Test"))), promise: promises.last ) promises.append(embedded.eventLoop.makePromise()) - embedded.pipeline.write(NIOAny(HTTPClientRequestPart.end(nil)), promise: promises.last) + embedded.pipeline.write(HTTPClientRequestPart.end(nil), promise: promises.last) embedded.pipeline.flush() // read the connect header back diff --git a/Tests/NIOExtrasTests/JSONRPCFramingContentLengthHeaderDecoderTests.swift b/Tests/NIOExtrasTests/JSONRPCFramingContentLengthHeaderDecoderTests.swift index 7c548bac..cd9605f1 100644 --- a/Tests/NIOExtrasTests/JSONRPCFramingContentLengthHeaderDecoderTests.swift +++ b/Tests/NIOExtrasTests/JSONRPCFramingContentLengthHeaderDecoderTests.swift @@ -25,9 +25,9 @@ final class JSONRPCFramingContentLengthHeaderDecoderTests: XCTestCase { // let's add the framing handler to the pipeline as that's what we're testing here. XCTAssertNoThrow( - try self.channel.pipeline.addHandler( + try self.channel.pipeline.syncOperations.addHandler( ByteToMessageHandler(NIOJSONRPCFraming.ContentLengthHeaderFrameDecoder()) - ).wait() + ) ) // this pretends to connect the channel to this IP address. XCTAssertNoThrow(self.channel.connect(to: try .init(ipAddress: "1.2.3.4", port: 5678))) diff --git a/Tests/NIOExtrasTests/JSONRPCFramingContentLengthHeaderEncoderTests.swift b/Tests/NIOExtrasTests/JSONRPCFramingContentLengthHeaderEncoderTests.swift index 68326052..76077d9a 100644 --- a/Tests/NIOExtrasTests/JSONRPCFramingContentLengthHeaderEncoderTests.swift +++ b/Tests/NIOExtrasTests/JSONRPCFramingContentLengthHeaderEncoderTests.swift @@ -25,13 +25,13 @@ final class JSONRPCFramingContentLengthHeaderEncoderTests: XCTestCase { // let's add the framing handler to the pipeline as that's what we're testing here. XCTAssertNoThrow( - try self.channel.pipeline.addHandler(NIOJSONRPCFraming.ContentLengthHeaderFrameEncoder()).wait() + try self.channel.pipeline.syncOperations.addHandler(NIOJSONRPCFraming.ContentLengthHeaderFrameEncoder()) ) // let's also add the decoder so we can round-trip XCTAssertNoThrow( - try self.channel.pipeline.addHandler( + try self.channel.pipeline.syncOperations.addHandler( ByteToMessageHandler(NIOJSONRPCFraming.ContentLengthHeaderFrameDecoder()) - ).wait() + ) ) // this pretends to connect the channel to this IP address. XCTAssertNoThrow(self.channel.connect(to: try .init(ipAddress: "1.2.3.4", port: 5678))) diff --git a/Tests/NIOExtrasTests/LengthFieldBasedFrameDecoderTest.swift b/Tests/NIOExtrasTests/LengthFieldBasedFrameDecoderTest.swift index 4647efbe..7a1e0a79 100644 --- a/Tests/NIOExtrasTests/LengthFieldBasedFrameDecoderTest.swift +++ b/Tests/NIOExtrasTests/LengthFieldBasedFrameDecoderTest.swift @@ -62,15 +62,15 @@ class LengthFieldBasedFrameDecoderTest: XCTestCase { XCTAssertEqual(buffer.read24UInt(endianness: .little), input) } } - func testDecodeWithUInt8HeaderWithData() throws { + func testDecodeWithUInt8HeaderWithData() throws { self.decoderUnderTest = .init( LengthFieldBasedFrameDecoder( lengthFieldLength: .one, lengthFieldEndianness: .little ) ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.decoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.decoderUnderTest)) let dataBytes: [UInt8] = [10, 20, 30, 40] let dataBytesLengthHeader = UInt8(dataBytes.count) @@ -100,7 +100,7 @@ class LengthFieldBasedFrameDecoderTest: XCTestCase { lengthFieldEndianness: .little ) ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.decoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.decoderUnderTest)) let dataLength: UInt16 = 5 @@ -129,7 +129,7 @@ class LengthFieldBasedFrameDecoderTest: XCTestCase { lengthFieldEndianness: .big ) ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.decoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.decoderUnderTest)) var buffer = self.channel.allocator.buffer(capacity: 8) // 3 byte header + 5 character string buffer.writeBytes([0, 0, 5]) @@ -156,7 +156,7 @@ class LengthFieldBasedFrameDecoderTest: XCTestCase { lengthFieldEndianness: .little ) ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.decoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.decoderUnderTest)) let dataLength: UInt32 = 5 @@ -185,7 +185,7 @@ class LengthFieldBasedFrameDecoderTest: XCTestCase { lengthFieldEndianness: .little ) ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.decoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.decoderUnderTest)) let dataLength: UInt64 = 5 @@ -214,7 +214,7 @@ class LengthFieldBasedFrameDecoderTest: XCTestCase { lengthFieldEndianness: .little ) ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.decoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.decoderUnderTest)) let dataLength: Int64 = 5 @@ -244,7 +244,7 @@ class LengthFieldBasedFrameDecoderTest: XCTestCase { lengthFieldEndianness: .big ) ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.decoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.decoderUnderTest)) let dataLength: Int64 = 5 @@ -269,7 +269,7 @@ class LengthFieldBasedFrameDecoderTest: XCTestCase { func testDecodeWithInt64HeaderStringDefaultingToBigEndian() throws { self.decoderUnderTest = .init(LengthFieldBasedFrameDecoder(lengthFieldLength: .eight)) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.decoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.decoderUnderTest)) let dataLength: Int64 = 5 @@ -298,7 +298,7 @@ class LengthFieldBasedFrameDecoderTest: XCTestCase { lengthFieldEndianness: .little ) ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.decoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.decoderUnderTest)) let firstFrameDataLength: UInt8 = 5 let secondFrameDataLength: UInt8 = 3 @@ -341,7 +341,7 @@ class LengthFieldBasedFrameDecoderTest: XCTestCase { lengthFieldEndianness: .little ) ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.decoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.decoderUnderTest)) let frameDataLength: UInt16 = 5 @@ -400,7 +400,7 @@ class LengthFieldBasedFrameDecoderTest: XCTestCase { lengthFieldEndianness: .little ) ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.decoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.decoderUnderTest)) let buffer = self.channel.allocator.buffer(capacity: 1) XCTAssertTrue(try self.channel.writeInbound(buffer).isEmpty) @@ -415,7 +415,7 @@ class LengthFieldBasedFrameDecoderTest: XCTestCase { lengthFieldEndianness: .little ) ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.decoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.decoderUnderTest)) let dataLength: UInt8 = 5 // 8 byte is only half the length required @@ -440,7 +440,7 @@ class LengthFieldBasedFrameDecoderTest: XCTestCase { lengthFieldEndianness: .little ) ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.decoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.decoderUnderTest)) let dataLength: UInt16 = 7 @@ -469,7 +469,7 @@ class LengthFieldBasedFrameDecoderTest: XCTestCase { lengthFieldEndianness: .little ) ) - try? self.channel.pipeline.addHandler(self.decoderUnderTest).wait() + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.decoderUnderTest)) let dataLength: Int64 = 5 @@ -479,7 +479,7 @@ class LengthFieldBasedFrameDecoderTest: XCTestCase { XCTAssertTrue(try self.channel.writeInbound(buffer).isFull) - let removeFuture = self.channel.pipeline.removeHandler(self.decoderUnderTest) + let removeFuture = self.channel.pipeline.syncOperations.removeHandler(self.decoderUnderTest) (channel.eventLoop as! EmbeddedEventLoop).run() XCTAssertNoThrow(try removeFuture.wait()) @@ -503,7 +503,7 @@ class LengthFieldBasedFrameDecoderTest: XCTestCase { lengthFieldEndianness: .little ) ) - try? self.channel.pipeline.addHandler(self.decoderUnderTest).wait() + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.decoderUnderTest)) let extraUnusedDataString = "fghi" let dataLength: Int64 = 5 @@ -514,7 +514,7 @@ class LengthFieldBasedFrameDecoderTest: XCTestCase { XCTAssertTrue(try channel.writeInbound(buffer).isFull) - let removeFuture = self.channel.pipeline.removeHandler(self.decoderUnderTest) + let removeFuture = self.channel.pipeline.syncOperations.removeHandler(self.decoderUnderTest) (channel.eventLoop as! EmbeddedEventLoop).run() XCTAssertNoThrow(try removeFuture.wait()) @@ -664,7 +664,7 @@ class LengthFieldBasedFrameDecoderTest: XCTestCase { lengthFieldEndianness: .little ) ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.decoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.decoderUnderTest)) let dataLength = UInt32(Int32.max) @@ -682,7 +682,7 @@ class LengthFieldBasedFrameDecoderTest: XCTestCase { lengthFieldEndianness: .little ) ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.decoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.decoderUnderTest)) let dataLength = UInt32(Int32.max) + 1 @@ -700,7 +700,7 @@ class LengthFieldBasedFrameDecoderTest: XCTestCase { lengthFieldEndianness: .little ) ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.decoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.decoderUnderTest)) let dataLength = UInt64(Int32.max) @@ -718,7 +718,7 @@ class LengthFieldBasedFrameDecoderTest: XCTestCase { lengthFieldEndianness: .little ) ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.decoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.decoderUnderTest)) let dataLength = UInt64(Int32.max) + 1 diff --git a/Tests/NIOExtrasTests/LengthFieldPrependerTest.swift b/Tests/NIOExtrasTests/LengthFieldPrependerTest.swift index aace8c04..da93df23 100644 --- a/Tests/NIOExtrasTests/LengthFieldPrependerTest.swift +++ b/Tests/NIOExtrasTests/LengthFieldPrependerTest.swift @@ -45,7 +45,7 @@ class LengthFieldPrependerTest: XCTestCase { lengthFieldEndianness: .little ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.encoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.encoderUnderTest)) let dataBytes: [UInt8] = [10, 20, 30, 40] @@ -85,7 +85,7 @@ class LengthFieldPrependerTest: XCTestCase { lengthFieldEndianness: endianness ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.encoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.encoderUnderTest)) var buffer = self.channel.allocator.buffer(capacity: standardDataStringCount) buffer.writeString(standardDataString) @@ -129,7 +129,7 @@ class LengthFieldPrependerTest: XCTestCase { lengthFieldEndianness: endianness ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.encoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.encoderUnderTest)) var buffer = self.channel.allocator.buffer(capacity: standardDataStringCount) buffer.writeString(standardDataString) @@ -173,7 +173,7 @@ class LengthFieldPrependerTest: XCTestCase { lengthFieldEndianness: endianness ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.encoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.encoderUnderTest)) var buffer = self.channel.allocator.buffer(capacity: standardDataStringCount) buffer.writeString(standardDataString) @@ -217,7 +217,7 @@ class LengthFieldPrependerTest: XCTestCase { lengthFieldEndianness: endianness ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.encoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.encoderUnderTest)) var buffer = self.channel.allocator.buffer(capacity: standardDataStringCount) buffer.writeString(standardDataString) @@ -258,7 +258,7 @@ class LengthFieldPrependerTest: XCTestCase { lengthFieldEndianness: endianness ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.encoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.encoderUnderTest)) var buffer = self.channel.allocator.buffer(capacity: standardDataStringCount) buffer.writeString(standardDataString) @@ -302,7 +302,7 @@ class LengthFieldPrependerTest: XCTestCase { lengthFieldEndianness: endianness ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.encoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.encoderUnderTest)) var buffer = self.channel.allocator.buffer(capacity: standardDataStringCount) buffer.writeString(standardDataString) @@ -341,7 +341,7 @@ class LengthFieldPrependerTest: XCTestCase { self.encoderUnderTest = LengthFieldPrepender(lengthFieldLength: .eight) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.encoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.encoderUnderTest)) var buffer = self.channel.allocator.buffer(capacity: standardDataStringCount) buffer.writeString(standardDataString) @@ -385,7 +385,7 @@ class LengthFieldPrependerTest: XCTestCase { lengthFieldEndianness: endianness ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.encoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.encoderUnderTest)) let buffer = self.channel.allocator.buffer(capacity: 0) @@ -421,7 +421,7 @@ class LengthFieldPrependerTest: XCTestCase { lengthFieldEndianness: endianness ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.encoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.encoderUnderTest)) let contents = [UInt8](repeating: 200, count: 514) @@ -465,7 +465,7 @@ class LengthFieldPrependerTest: XCTestCase { lengthFieldEndianness: endianness ) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.encoderUnderTest).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.encoderUnderTest)) let contents = [UInt8](repeating: 200, count: 300) diff --git a/Tests/NIOExtrasTests/LineBasedFrameDecoderTest.swift b/Tests/NIOExtrasTests/LineBasedFrameDecoderTest.swift index 8923f60f..9a9bb0be 100644 --- a/Tests/NIOExtrasTests/LineBasedFrameDecoderTest.swift +++ b/Tests/NIOExtrasTests/LineBasedFrameDecoderTest.swift @@ -28,7 +28,7 @@ class LineBasedFrameDecoderTest: XCTestCase { self.channel = EmbeddedChannel() self.decoder = LineBasedFrameDecoder() self.handler = ByteToMessageHandler(self.decoder) - XCTAssertNoThrow(try self.channel.pipeline.addHandler(self.handler).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(self.handler)) } override func tearDown() { @@ -69,7 +69,7 @@ class LineBasedFrameDecoderTest: XCTestCase { XCTAssertEqual(3, outputBuffer?.readableBytes) XCTAssertEqual("foo", outputBuffer?.readString(length: 3)) - let removeFuture = self.channel.pipeline.removeHandler(self.handler) + let removeFuture = self.channel.pipeline.syncOperations.removeHandler(self.handler) (self.channel.eventLoop as! EmbeddedEventLoop).run() XCTAssertNoThrow(try removeFuture.wait()) XCTAssertThrowsError(try self.channel.throwIfErrorCaught()) { error in @@ -93,7 +93,7 @@ class LineBasedFrameDecoderTest: XCTestCase { var outputBuffer: ByteBuffer? = try self.channel.readInbound() XCTAssertEqual("foo", outputBuffer?.readString(length: 3)) - let removeFuture = self.channel.pipeline.removeHandler(self.handler) + let removeFuture = self.channel.pipeline.syncOperations.removeHandler(self.handler) (self.channel.eventLoop as! EmbeddedEventLoop).run() XCTAssertNoThrow(try removeFuture.wait()) XCTAssertNoThrow(try self.channel.throwIfErrorCaught()) diff --git a/Tests/NIOExtrasTests/PCAPRingBufferTest.swift b/Tests/NIOExtrasTests/PCAPRingBufferTest.swift index cd4ddff3..5b6f8b84 100644 --- a/Tests/NIOExtrasTests/PCAPRingBufferTest.swift +++ b/Tests/NIOExtrasTests/PCAPRingBufferTest.swift @@ -126,14 +126,14 @@ class PCAPRingBufferTest: XCTestCase { let channel = EmbeddedChannel() let ringBuffer = NIOPCAPRingBuffer(maximumFragments: .init(fragmentsToRecord), maximumBytes: 1_000_000) XCTAssertNoThrow( - try channel.pipeline.addHandler( + try channel.pipeline.syncOperations.addHandler( NIOWritePCAPHandler( mode: .client, fakeLocalAddress: nil, fakeRemoteAddress: nil, fileSink: { ringBuffer.addFragment($0) } ) - ).wait() + ) ) channel.localAddress = try! SocketAddress(ipAddress: "255.255.255.254", port: Int(UInt16.max) - 1) XCTAssertNoThrow(try channel.connect(to: .init(ipAddress: "1.2.3.4", port: 5678)).wait()) diff --git a/Tests/NIOExtrasTests/QuiescingHelperTest.swift b/Tests/NIOExtrasTests/QuiescingHelperTest.swift index 68c9cf4d..a8a6d3cc 100644 --- a/Tests/NIOExtrasTests/QuiescingHelperTest.swift +++ b/Tests/NIOExtrasTests/QuiescingHelperTest.swift @@ -70,7 +70,7 @@ public class QuiescingHelperTest: XCTestCase { XCTAssertNoThrow(try channel.connect(to: .init(ipAddress: "1.2.3.4", port: pretendPort)).wait()) waitForFutures.append(waitForPromise.futureResult) childChannels.append(channel) - serverChannel.pipeline.fireChannelRead(NIOAny(channel)) + serverChannel.pipeline.fireChannelRead(channel) } // check that the server channel and all child channels are active before initiating the shutdown XCTAssertTrue(serverChannel.isActive) @@ -201,7 +201,7 @@ public class QuiescingHelperTest: XCTestCase { let childChannel1 = EmbeddedChannel(handler: eventCounterHandler, loop: el) // activate the child channel XCTAssertNoThrow(try childChannel1.connect(to: .init(ipAddress: "1.2.3.4", port: 1)).wait()) - serverChannel.pipeline.fireChannelRead(NIOAny(childChannel1)) + serverChannel.pipeline.fireChannelRead(childChannel1) // check that the server channel and channel are active before initiating the shutdown XCTAssertTrue(serverChannel.isActive) @@ -244,7 +244,7 @@ public class QuiescingHelperTest: XCTestCase { let childChannel1 = EmbeddedChannel(handler: WaitForQuiesceUserEvent(promise: waitForPromise1), loop: el) // activate the child channel XCTAssertNoThrow(try childChannel1.connect(to: .init(ipAddress: "1.2.3.4", port: 1)).wait()) - serverChannel.pipeline.fireChannelRead(NIOAny(childChannel1)) + serverChannel.pipeline.fireChannelRead(childChannel1) el.run() @@ -260,7 +260,7 @@ public class QuiescingHelperTest: XCTestCase { let childChannel2 = EmbeddedChannel(handler: WaitForQuiesceUserEvent(promise: waitForPromise2), loop: el) // activate the child channel XCTAssertNoThrow(try childChannel2.connect(to: .init(ipAddress: "1.2.3.4", port: 2)).wait()) - serverChannel.pipeline.fireChannelRead(NIOAny(childChannel2)) + serverChannel.pipeline.fireChannelRead(childChannel2) el.run() // Check that we got all quiescing events @@ -308,7 +308,7 @@ public class QuiescingHelperTest: XCTestCase { let childChannel1 = EmbeddedChannel(loop: el) // activate the child channel XCTAssertNoThrow(try childChannel1.connect(to: .init(ipAddress: "1.2.3.4", port: 1)).wait()) - serverChannel.pipeline.fireChannelRead(NIOAny(childChannel1)) + serverChannel.pipeline.fireChannelRead(childChannel1) el.run() } diff --git a/Tests/NIOExtrasTests/RequestResponseHandlerTest.swift b/Tests/NIOExtrasTests/RequestResponseHandlerTest.swift index 20ed1bae..401a75d7 100644 --- a/Tests/NIOExtrasTests/RequestResponseHandlerTest.swift +++ b/Tests/NIOExtrasTests/RequestResponseHandlerTest.swift @@ -41,7 +41,7 @@ class RequestResponseHandlerTest: XCTestCase { } func testSimpleRequestWorks() { - XCTAssertNoThrow(try self.channel.pipeline.addHandler(RequestResponseHandler()).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(RequestResponseHandler())) self.buffer.writeString("hello") // pretend to connect to the EmbeddedChannel knows it's supposed to be active @@ -62,7 +62,7 @@ class RequestResponseHandlerTest: XCTestCase { func testEnqueingMultipleRequestsWorks() throws { struct DummyError: Error {} - XCTAssertNoThrow(try self.channel.pipeline.addHandler(RequestResponseHandler()).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(RequestResponseHandler())) var futures: [EventLoopFuture] = [] // pretend to connect to the EmbeddedChannel knows it's supposed to be active @@ -114,7 +114,7 @@ class RequestResponseHandlerTest: XCTestCase { func testRequestsEnqueuedAfterErrorAreFailed() { struct DummyError: Error {} - XCTAssertNoThrow(try self.channel.pipeline.addHandler(RequestResponseHandler()).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(RequestResponseHandler())) self.channel.pipeline.fireErrorCaught(DummyError()) @@ -131,7 +131,7 @@ class RequestResponseHandlerTest: XCTestCase { struct DummyError1: Error {} struct DummyError2: Error {} - XCTAssertNoThrow(try self.channel.pipeline.addHandler(RequestResponseHandler()).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(RequestResponseHandler())) let p: EventLoopPromise = self.eventLoop.makePromise() // right now, everything's still okay so the enqueued request won't immediately be failed @@ -152,7 +152,7 @@ class RequestResponseHandlerTest: XCTestCase { } func testClosedConnectionFailsOutstandingPromises() { - XCTAssertNoThrow(try self.channel.pipeline.addHandler(RequestResponseHandler()).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(RequestResponseHandler())) let promise = self.eventLoop.makePromise(of: Void.self) XCTAssertNoThrow(try self.channel.writeOutbound(("Hello!", promise))) diff --git a/Tests/NIOExtrasTests/SynchronizedFileSinkTests.swift b/Tests/NIOExtrasTests/SynchronizedFileSinkTests.swift index 5f806322..3e920cfe 100644 --- a/Tests/NIOExtrasTests/SynchronizedFileSinkTests.swift +++ b/Tests/NIOExtrasTests/SynchronizedFileSinkTests.swift @@ -72,7 +72,7 @@ private func withTemporaryFile( XCTAssertNoThrow(try FileManager.default.removeItem(atPath: temporaryFilePath)) } - let fileHandle = try NIOFileHandle(path: temporaryFilePath, mode: [.read, .write]) + let fileHandle = try NIOFileHandle(_deprecatedPath: temporaryFilePath, mode: [.read, .write]) defer { XCTAssertNoThrow(try fileHandle.close()) } @@ -91,7 +91,13 @@ private func withTemporaryFile( XCTAssertNoThrow(try FileManager.default.removeItem(atPath: temporaryFilePath)) } - let fileHandle = try NIOFileHandle(path: temporaryFilePath, mode: [.read, .write]) + // NIOFileHandle(_deprecatedPath:mode:) is 'noasync' but we don't have a viable alternative; + // this wrapper suppresses the 'noasync'. + func makeFileHandle() throws -> NIOFileHandle { + try NIOFileHandle(_deprecatedPath: temporaryFilePath, mode: [.read, .write]) + } + + let fileHandle = try makeFileHandle() defer { XCTAssertNoThrow(try fileHandle.close()) } diff --git a/Tests/NIOExtrasTests/WritePCAPHandlerTest.swift b/Tests/NIOExtrasTests/WritePCAPHandlerTest.swift index 7d2173c1..1d44a10c 100644 --- a/Tests/NIOExtrasTests/WritePCAPHandlerTest.swift +++ b/Tests/NIOExtrasTests/WritePCAPHandlerTest.swift @@ -49,7 +49,7 @@ class WritePCAPHandlerTest: XCTestCase { self.accumulatedPackets = [] self.channel = EmbeddedChannel() XCTAssertNoThrow( - try self.channel.pipeline.addHandler( + try self.channel.pipeline.syncOperations.addHandler( NIOWritePCAPHandler( mode: .client, fakeLocalAddress: nil, @@ -59,7 +59,7 @@ class WritePCAPHandlerTest: XCTestCase { } ), name: "NIOWritePCAPHandler" - ).wait() + ) ) self.scratchBuffer = self.channel.allocator.buffer(capacity: 128) } @@ -731,7 +731,7 @@ class WritePCAPHandlerTest: XCTestCase { XCTAssertNoThrow(try self.channel.pipeline.removeHandler(name: "NIOWritePCAPHandler").wait()) let settings = NIOWritePCAPHandler.Settings(emitPCAPWrites: .whenIssued) XCTAssertNoThrow( - try self.channel.pipeline.addHandler( + try self.channel.pipeline.syncOperations.addHandler( NIOWritePCAPHandler( mode: .client, fakeLocalAddress: nil, @@ -741,7 +741,7 @@ class WritePCAPHandlerTest: XCTestCase { self.accumulatedPackets.append($0) } ) - ).wait() + ) ) self.channel.localAddress = try! SocketAddress(ipAddress: "1.2.3.4", port: 1111) self.channel.remoteAddress = try! SocketAddress(ipAddress: "9.8.7.6", port: 2222) @@ -779,7 +779,7 @@ class WritePCAPHandlerTest: XCTestCase { // Let's drop all writes/flushes so EmbeddedChannel won't accumulate them. XCTAssertNoThrow(try channel.pipeline.addHandler(DropAllWritesAndFlushes()).wait()) XCTAssertNoThrow( - try channel.pipeline.addHandler( + try channel.pipeline.syncOperations.addHandler( NIOWritePCAPHandler( mode: .client, fakeLocalAddress: .init(ipAddress: "::1", port: 1), @@ -788,7 +788,7 @@ class WritePCAPHandlerTest: XCTestCase { numberOfBytesLogged += Int64($0.readableBytes) } ) - ).wait() + ) ) // Let's also drop all channelReads to prevent accumulation of all the data. XCTAssertNoThrow(try channel.pipeline.addHandler(DropAllChannelReads()).wait()) diff --git a/Tests/NIOHTTPCompressionTests/HTTPRequestCompressorTest.swift b/Tests/NIOHTTPCompressionTests/HTTPRequestCompressorTest.swift index 6954d9a9..baebe4e5 100644 --- a/Tests/NIOHTTPCompressionTests/HTTPRequestCompressorTest.swift +++ b/Tests/NIOHTTPCompressionTests/HTTPRequestCompressorTest.swift @@ -26,7 +26,10 @@ class HTTPRequestCompressorTest: XCTestCase { let channel = EmbeddedChannel() //XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestEncoder(), name: "encoder").wait()) XCTAssertNoThrow( - try channel.pipeline.addHandler(NIOHTTPRequestCompressor(encoding: compression), name: "compressor").wait() + try channel.pipeline.syncOperations.addHandler( + NIOHTTPRequestCompressor(encoding: compression), + name: "compressor" + ) ) return channel } @@ -38,15 +41,15 @@ class HTTPRequestCompressorTest: XCTestCase { func write(head: HTTPRequestHead, body: [ByteBuffer], to channel: EmbeddedChannel) throws { var promiseArray = PromiseArray(on: channel.eventLoop) - channel.pipeline.write(NIOAny(HTTPClientRequestPart.head(head)), promise: promiseArray.makePromise()) + channel.pipeline.write(HTTPClientRequestPart.head(head), promise: promiseArray.makePromise()) for bodyChunk in body { channel.pipeline.write( - NIOAny(HTTPClientRequestPart.body(.byteBuffer(bodyChunk))), + HTTPClientRequestPart.body(.byteBuffer(bodyChunk)), promise: promiseArray.makePromise() ) } - channel.pipeline.write(NIOAny(HTTPClientRequestPart.end(nil)), promise: promiseArray.makePromise()) + channel.pipeline.write(HTTPClientRequestPart.end(nil), promise: promiseArray.makePromise()) channel.pipeline.flush() try promiseArray.waitUntilComplete() @@ -60,11 +63,11 @@ class HTTPRequestCompressorTest: XCTestCase { func writeWithIntermittantFlush(head: HTTPRequestHead, body: [ByteBuffer], to channel: EmbeddedChannel) throws { var promiseArray = PromiseArray(on: channel.eventLoop) var count = 3 - channel.pipeline.write(NIOAny(HTTPClientRequestPart.head(head)), promise: promiseArray.makePromise()) + channel.pipeline.write(HTTPClientRequestPart.head(head), promise: promiseArray.makePromise()) for bodyChunk in body { channel.pipeline.write( - NIOAny(HTTPClientRequestPart.body(.byteBuffer(bodyChunk))), + HTTPClientRequestPart.body(.byteBuffer(bodyChunk)), promise: promiseArray.makePromise() ) count -= 1 @@ -73,7 +76,7 @@ class HTTPRequestCompressorTest: XCTestCase { count = 3 } } - channel.pipeline.write(NIOAny(HTTPClientRequestPart.end(nil)), promise: promiseArray.makePromise()) + channel.pipeline.write(HTTPClientRequestPart.end(nil), promise: promiseArray.makePromise()) channel.pipeline.flush() try promiseArray.waitUntilComplete() @@ -225,13 +228,13 @@ class HTTPRequestCompressorTest: XCTestCase { let requestHead = HTTPRequestHead(version: HTTPVersion(major: 1, minor: 1), method: .GET, uri: "/") var promiseArray = PromiseArray(on: channel.eventLoop) - channel.pipeline.write(NIOAny(HTTPClientRequestPart.head(requestHead)), promise: promiseArray.makePromise()) + channel.pipeline.write(HTTPClientRequestPart.head(requestHead), promise: promiseArray.makePromise()) channel.pipeline.flush() channel.pipeline.write( - NIOAny(HTTPClientRequestPart.body(.byteBuffer(buffer))), + HTTPClientRequestPart.body(.byteBuffer(buffer)), promise: promiseArray.makePromise() ) - channel.pipeline.write(NIOAny(HTTPClientRequestPart.end(nil)), promise: promiseArray.makePromise()) + channel.pipeline.write(HTTPClientRequestPart.end(nil), promise: promiseArray.makePromise()) channel.pipeline.flush() try promiseArray.waitUntilComplete() @@ -252,13 +255,13 @@ class HTTPRequestCompressorTest: XCTestCase { let requestHead = HTTPRequestHead(version: HTTPVersion(major: 1, minor: 1), method: .GET, uri: "/") var promiseArray = PromiseArray(on: channel.eventLoop) - channel.pipeline.write(NIOAny(HTTPClientRequestPart.head(requestHead)), promise: promiseArray.makePromise()) + channel.pipeline.write(HTTPClientRequestPart.head(requestHead), promise: promiseArray.makePromise()) channel.pipeline.write( - NIOAny(HTTPClientRequestPart.body(.byteBuffer(buffer))), + HTTPClientRequestPart.body(.byteBuffer(buffer)), promise: promiseArray.makePromise() ) channel.pipeline.flush() - channel.pipeline.write(NIOAny(HTTPClientRequestPart.end(nil)), promise: promiseArray.makePromise()) + channel.pipeline.write(HTTPClientRequestPart.end(nil), promise: promiseArray.makePromise()) channel.pipeline.flush() try promiseArray.waitUntilComplete() @@ -283,14 +286,14 @@ class HTTPRequestCompressorTest: XCTestCase { } let requestHead = HTTPRequestHead(version: HTTPVersion(major: 1, minor: 1), method: .GET, uri: "/") var promiseArray = PromiseArray(on: channel.eventLoop) - channel.pipeline.write(NIOAny(HTTPClientRequestPart.head(requestHead)), promise: promiseArray.makePromise()) + channel.pipeline.write(HTTPClientRequestPart.head(requestHead), promise: promiseArray.makePromise()) channel.pipeline.write( - NIOAny(HTTPClientRequestPart.body(.byteBuffer(buffer))), + HTTPClientRequestPart.body(.byteBuffer(buffer)), promise: promiseArray.makePromise() ) channel.pipeline.flush() channel.pipeline.flush() - channel.pipeline.write(NIOAny(HTTPClientRequestPart.end(nil)), promise: promiseArray.makePromise()) + channel.pipeline.write(HTTPClientRequestPart.end(nil), promise: promiseArray.makePromise()) channel.pipeline.flush() try promiseArray.waitUntilComplete() @@ -307,8 +310,8 @@ class HTTPRequestCompressorTest: XCTestCase { let requestHead = HTTPRequestHead(version: HTTPVersion(major: 1, minor: 1), method: .GET, uri: "/") var promiseArray = PromiseArray(on: channel.eventLoop) - channel.pipeline.write(NIOAny(HTTPClientRequestPart.head(requestHead)), promise: promiseArray.makePromise()) - channel.pipeline.write(NIOAny(HTTPClientRequestPart.end(nil)), promise: promiseArray.makePromise()) + channel.pipeline.write(HTTPClientRequestPart.head(requestHead), promise: promiseArray.makePromise()) + channel.pipeline.write(HTTPClientRequestPart.end(nil), promise: promiseArray.makePromise()) channel.pipeline.flush() try promiseArray.waitUntilComplete() diff --git a/Tests/NIOHTTPCompressionTests/HTTPRequestDecompressorTest.swift b/Tests/NIOHTTPCompressionTests/HTTPRequestDecompressorTest.swift index 94190e94..b7b93ebc 100644 --- a/Tests/NIOHTTPCompressionTests/HTTPRequestDecompressorTest.swift +++ b/Tests/NIOHTTPCompressionTests/HTTPRequestDecompressorTest.swift @@ -44,8 +44,8 @@ private final class DecompressedAssert: ChannelInboundHandler { class HTTPRequestDecompressorTest: XCTestCase { func testDecompressionNoLimit() throws { let channel = EmbeddedChannel() - try channel.pipeline.addHandler(NIOHTTPRequestDecompressor(limit: .none)).wait() - try channel.pipeline.addHandler(DecompressedAssert()).wait() + try channel.pipeline.syncOperations.addHandler(NIOHTTPRequestDecompressor(limit: .none)) + try channel.pipeline.syncOperations.addHandler(DecompressedAssert()) let buffer = ByteBuffer.of(string: testString) let compressed = compress(buffer, "gzip") @@ -67,7 +67,7 @@ class HTTPRequestDecompressorTest: XCTestCase { func testDecompressionLimitRatio() throws { let channel = EmbeddedChannel() - try channel.pipeline.addHandler(NIOHTTPRequestDecompressor(limit: .ratio(10))).wait() + try channel.pipeline.syncOperations.addHandler(NIOHTTPRequestDecompressor(limit: .ratio(10))) let decompressed = ByteBuffer.of(bytes: Array(repeating: 0, count: 500)) let compressed = compress(decompressed, "gzip") let headers = HTTPHeaders([("Content-Encoding", "gzip"), ("Content-Length", "\(compressed.readableBytes)")]) @@ -100,7 +100,9 @@ class HTTPRequestDecompressorTest: XCTestCase { let channel = EmbeddedChannel() let decompressed = ByteBuffer.of(bytes: Array(repeating: 0, count: 200)) let compressed = compress(decompressed, "gzip") - try channel.pipeline.addHandler(NIOHTTPRequestDecompressor(limit: .size(decompressed.readableBytes - 1))).wait() + try channel.pipeline.syncOperations.addHandler( + NIOHTTPRequestDecompressor(limit: .size(decompressed.readableBytes - 1)) + ) let headers = HTTPHeaders([("Content-Encoding", "gzip"), ("Content-Length", "\(compressed.readableBytes)")]) try channel.writeInbound( HTTPServerRequestPart.head( @@ -129,7 +131,7 @@ class HTTPRequestDecompressorTest: XCTestCase { func testDecompression() throws { let channel = EmbeddedChannel() - try channel.pipeline.addHandler(NIOHTTPRequestDecompressor(limit: .none)).wait() + try channel.pipeline.syncOperations.addHandler(NIOHTTPRequestDecompressor(limit: .none)) let body = Array(repeating: testString, count: 1000).joined() let algorithms: [(actual: String, announced: String)?] = [ @@ -174,7 +176,7 @@ class HTTPRequestDecompressorTest: XCTestCase { let compressed = ByteBuffer(bytes: [120, 156, 99, 0, 0, 0, 1, 0, 1] + [1, 2, 3]) let channel = EmbeddedChannel() - try channel.pipeline.addHandler(NIOHTTPRequestDecompressor(limit: .none)).wait() + try channel.pipeline.syncOperations.addHandler(NIOHTTPRequestDecompressor(limit: .none)) let headers = HTTPHeaders([("Content-Encoding", "deflate"), ("Content-Length", "\(compressed.readableBytes)")]) try channel.writeInbound( HTTPServerRequestPart.head( @@ -195,7 +197,7 @@ class HTTPRequestDecompressorTest: XCTestCase { let compressed = ByteBuffer(bytes: [120, 156, 99, 0]) let channel = EmbeddedChannel() - try channel.pipeline.addHandler(NIOHTTPRequestDecompressor(limit: .none)).wait() + try channel.pipeline.syncOperations.addHandler(NIOHTTPRequestDecompressor(limit: .none)) let headers = HTTPHeaders([("Content-Encoding", "deflate"), ("Content-Length", "\(compressed.readableBytes)")]) try channel.writeInbound( HTTPServerRequestPart.head( diff --git a/Tests/NIOHTTPCompressionTests/HTTPResponseCompressorTest.swift b/Tests/NIOHTTPCompressionTests/HTTPResponseCompressorTest.swift index cc32ecdc..75f67136 100644 --- a/Tests/NIOHTTPCompressionTests/HTTPResponseCompressorTest.swift +++ b/Tests/NIOHTTPCompressionTests/HTTPResponseCompressorTest.swift @@ -151,17 +151,17 @@ class HTTPResponseCompressorTest: XCTestCase { private func writeOneChunk(head: HTTPResponseHead, body: [ByteBuffer], channel: EmbeddedChannel) throws { let promiseOrderer = PromiseOrderer(eventLoop: channel.eventLoop) - channel.pipeline.write(NIOAny(HTTPServerResponsePart.head(head)), promise: promiseOrderer.makePromise()) + channel.pipeline.write(HTTPServerResponsePart.head(head), promise: promiseOrderer.makePromise()) for bodyChunk in body { channel.pipeline.write( - NIOAny(HTTPServerResponsePart.body(.byteBuffer(bodyChunk))), + HTTPServerResponsePart.body(.byteBuffer(bodyChunk)), promise: promiseOrderer.makePromise() ) } channel.pipeline.write( - NIOAny(HTTPServerResponsePart.end(nil)), + HTTPServerResponsePart.end(nil), promise: promiseOrderer.makePromise() ) channel.pipeline.flush() @@ -173,9 +173,9 @@ class HTTPResponseCompressorTest: XCTestCase { private func writeIntermittentFlushes(head: HTTPResponseHead, body: [ByteBuffer], channel: EmbeddedChannel) throws { let promiseOrderer = PromiseOrderer(eventLoop: channel.eventLoop) var writeCount = 0 - channel.pipeline.write(NIOAny(HTTPServerResponsePart.head(head)), promise: promiseOrderer.makePromise()) + channel.pipeline.write(HTTPServerResponsePart.head(head), promise: promiseOrderer.makePromise()) for bodyChunk in body { - channel.pipeline.write( + channel.pipeline.syncOperations.write( NIOAny(HTTPServerResponsePart.body(.byteBuffer(bodyChunk))), promise: promiseOrderer.makePromise() ) @@ -185,7 +185,7 @@ class HTTPResponseCompressorTest: XCTestCase { } } channel.pipeline.write( - NIOAny(HTTPServerResponsePart.end(nil)), + HTTPServerResponsePart.end(nil), promise: promiseOrderer.makePromise() ) channel.pipeline.flush() @@ -215,8 +215,8 @@ class HTTPResponseCompressorTest: XCTestCase { } var requestHead = HTTPRequestHead(version: HTTPVersion(major: 1, minor: 1), method: .GET, uri: "/") requestHead.headers.add(name: "host", value: "apple.com") - clientChannel.write(NIOAny(HTTPClientRequestPart.head(requestHead)), promise: nil) - clientChannel.write(NIOAny(HTTPClientRequestPart.end(nil)), promise: nil) + clientChannel.write(HTTPClientRequestPart.head(requestHead), promise: nil) + clientChannel.write(HTTPClientRequestPart.end(nil), promise: nil) while let b = try channel.readOutbound(as: ByteBuffer.self) { try clientChannel.writeInbound(b) @@ -406,8 +406,8 @@ class HTTPResponseCompressorTest: XCTestCase { compressor: HTTPResponseCompressor = HTTPResponseCompressor() ) throws -> EmbeddedChannel { let channel = EmbeddedChannel() - XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPResponseEncoder(), name: "encoder").wait()) - XCTAssertNoThrow(try channel.pipeline.addHandler(compressor, name: "compressor").wait()) + XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(HTTPResponseEncoder(), name: "encoder")) + XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(compressor, name: "compressor")) return channel } @@ -593,7 +593,7 @@ class HTTPResponseCompressorTest: XCTestCase { try sendRequest(acceptEncoding: "gzip", channel: channel) let head = HTTPResponseHead(version: HTTPVersion(major: 1, minor: 1), status: .ok) let writePromise = channel.eventLoop.makePromise(of: Void.self) - channel.write(NIOAny(HTTPServerResponsePart.head(head)), promise: writePromise) + channel.write(HTTPServerResponsePart.head(head), promise: writePromise) writePromise.futureResult.map { XCTFail("Write succeeded") }.whenFailure { err in @@ -621,7 +621,7 @@ class HTTPResponseCompressorTest: XCTestCase { try sendRequest(acceptEncoding: nil, channel: channel) let head = HTTPResponseHead(version: HTTPVersion(major: 1, minor: 1), status: .ok) let writePromise = channel.eventLoop.makePromise(of: Void.self) - channel.writeAndFlush(NIOAny(HTTPServerResponsePart.head(head)), promise: writePromise) + channel.writeAndFlush(HTTPServerResponsePart.head(head), promise: writePromise) XCTAssertNoThrow(try channel.pipeline.removeHandler(name: "encoder").wait()) XCTAssertNoThrow(try channel.pipeline.removeHandler(name: "compressor").wait()) @@ -636,9 +636,9 @@ class HTTPResponseCompressorTest: XCTestCase { var bodyBuffer = channel.allocator.buffer(capacity: 20) bodyBuffer.writeBytes([UInt8](repeating: 60, count: 20)) - channel.write(NIOAny(HTTPServerResponsePart.head(head)), promise: nil) - channel.writeAndFlush(NIOAny(HTTPServerResponsePart.body(.byteBuffer(bodyBuffer))), promise: nil) - channel.writeAndFlush(NIOAny(HTTPServerResponsePart.end(nil)), promise: finalPromise) + channel.write(HTTPServerResponsePart.head(head), promise: nil) + channel.writeAndFlush(HTTPServerResponsePart.body(.byteBuffer(bodyBuffer)), promise: nil) + channel.writeAndFlush(HTTPServerResponsePart.end(nil), promise: finalPromise) try finalPromise.futureResult.wait() @@ -708,11 +708,8 @@ class HTTPResponseCompressorTest: XCTestCase { try sendRequest(acceptEncoding: "deflate", channel: channel) try assertDeflatedResponse(channel: channel) - XCTAssertNoThrow( - try channel.pipeline.context(handlerType: HTTPResponseCompressor.self).flatMap { context in - channel.pipeline.removeHandler(context: context) - }.wait() - ) + let context = try channel.pipeline.syncOperations.context(handlerType: HTTPResponseCompressor.self) + XCTAssertNoThrow(try channel.pipeline.syncOperations.removeHandler(context: context).wait()) try sendRequest(acceptEncoding: "deflate", channel: channel) try assertUncompressedResponse(channel: channel) @@ -720,7 +717,7 @@ class HTTPResponseCompressorTest: XCTestCase { func testBypassCompressionWhenNoContent() throws { let channel = EmbeddedChannel() - XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPResponseCompressor()).wait()) + XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(HTTPResponseCompressor())) defer { XCTAssertNoThrow(try channel.finish()) } @@ -748,7 +745,7 @@ class HTTPResponseCompressorTest: XCTestCase { func testBypassCompressionWhenNotModified() throws { let channel = EmbeddedChannel() - XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPResponseCompressor()).wait()) + XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(HTTPResponseCompressor())) defer { XCTAssertNoThrow(try channel.finish()) } @@ -840,7 +837,7 @@ class HTTPResponseCompressorTest: XCTestCase { } let channel = EmbeddedChannel() - XCTAssertNoThrow(try channel.pipeline.addHandler(compressor).wait()) + XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(compressor)) defer { XCTAssertNoThrow(try channel.finish()) } @@ -933,7 +930,7 @@ class HTTPResponseCompressorTest: XCTestCase { } let channel = EmbeddedChannel() - XCTAssertNoThrow(try channel.pipeline.addHandler(compressor).wait()) + XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(compressor)) defer { XCTAssertNoThrow(try channel.finish()) } diff --git a/Tests/NIOHTTPCompressionTests/HTTPResponseDecompressorTest.swift b/Tests/NIOHTTPCompressionTests/HTTPResponseDecompressorTest.swift index 8a268502..54b683a1 100644 --- a/Tests/NIOHTTPCompressionTests/HTTPResponseDecompressorTest.swift +++ b/Tests/NIOHTTPCompressionTests/HTTPResponseDecompressorTest.swift @@ -23,7 +23,7 @@ import XCTest class HTTPResponseDecompressorTest: XCTestCase { func testDecompressionNoLimit() throws { let channel = EmbeddedChannel() - try channel.pipeline.addHandler(NIOHTTPResponseDecompressor(limit: .none)).wait() + try channel.pipeline.syncOperations.addHandler(NIOHTTPResponseDecompressor(limit: .none)) let headers = HTTPHeaders([("Content-Encoding", "deflate"), ("Content-Length", "13")]) try channel.writeInbound( @@ -36,7 +36,7 @@ class HTTPResponseDecompressorTest: XCTestCase { func testDecompressionLimitSizeWithContentLenghtHeaderSucceeds() { let channel = EmbeddedChannel() - XCTAssertNoThrow(try channel.pipeline.addHandler(NIOHTTPResponseDecompressor(limit: .size(272))).wait()) + XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(NIOHTTPResponseDecompressor(limit: .size(272)))) let headers = HTTPHeaders([("Content-Encoding", "deflate"), ("Content-Length", "13")]) @@ -53,7 +53,7 @@ class HTTPResponseDecompressorTest: XCTestCase { func testDecompressionLimitSizeWithContentLenghtHeaderFails() { let channel = EmbeddedChannel() - XCTAssertNoThrow(try channel.pipeline.addHandler(NIOHTTPResponseDecompressor(limit: .size(271))).wait()) + XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(NIOHTTPResponseDecompressor(limit: .size(271)))) let headers = HTTPHeaders([("Content-Encoding", "deflate"), ("Content-Length", "13")]) @@ -72,7 +72,7 @@ class HTTPResponseDecompressorTest: XCTestCase { func testDecompressionLimitSizeWithoutContentLenghtHeaderSucceeds() { let channel = EmbeddedChannel() - XCTAssertNoThrow(try channel.pipeline.addHandler(NIOHTTPResponseDecompressor(limit: .size(272))).wait()) + XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(NIOHTTPResponseDecompressor(limit: .size(272)))) let headers = HTTPHeaders([("Content-Encoding", "deflate")]) @@ -89,7 +89,7 @@ class HTTPResponseDecompressorTest: XCTestCase { func testDecompressionLimitSizeWithoutContentLenghtHeaderFails() { let channel = EmbeddedChannel() - XCTAssertNoThrow(try channel.pipeline.addHandler(NIOHTTPResponseDecompressor(limit: .size(271))).wait()) + XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(NIOHTTPResponseDecompressor(limit: .size(271)))) let headers = HTTPHeaders([("Content-Encoding", "deflate")]) @@ -108,7 +108,7 @@ class HTTPResponseDecompressorTest: XCTestCase { func testDecompressionLimitRatioWithContentLenghtHeaderSucceeds() { let channel = EmbeddedChannel() - XCTAssertNoThrow(try channel.pipeline.addHandler(NIOHTTPResponseDecompressor(limit: .ratio(21))).wait()) + XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(NIOHTTPResponseDecompressor(limit: .ratio(21)))) let headers = HTTPHeaders([("Content-Encoding", "deflate"), ("Content-Length", "13")]) @@ -125,7 +125,7 @@ class HTTPResponseDecompressorTest: XCTestCase { func testDecompressionLimitRatioWithContentLenghtHeaderFails() { let channel = EmbeddedChannel() - XCTAssertNoThrow(try channel.pipeline.addHandler(NIOHTTPResponseDecompressor(limit: .ratio(20))).wait()) + XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(NIOHTTPResponseDecompressor(limit: .ratio(20)))) let headers = HTTPHeaders([("Content-Encoding", "deflate"), ("Content-Length", "13")]) @@ -144,7 +144,7 @@ class HTTPResponseDecompressorTest: XCTestCase { func testDecompressionLimitRatioWithoutContentLenghtHeaderSucceeds() { let channel = EmbeddedChannel() - XCTAssertNoThrow(try channel.pipeline.addHandler(NIOHTTPResponseDecompressor(limit: .ratio(21))).wait()) + XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(NIOHTTPResponseDecompressor(limit: .ratio(21)))) let headers = HTTPHeaders([("Content-Encoding", "deflate")]) @@ -161,7 +161,7 @@ class HTTPResponseDecompressorTest: XCTestCase { func testDecompressionLimitRatioWithoutContentLenghtHeaderFails() { let channel = EmbeddedChannel() - XCTAssertNoThrow(try channel.pipeline.addHandler(NIOHTTPResponseDecompressor(limit: .ratio(20))).wait()) + XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(NIOHTTPResponseDecompressor(limit: .ratio(20)))) let headers = HTTPHeaders([("Content-Encoding", "deflate")]) @@ -180,7 +180,7 @@ class HTTPResponseDecompressorTest: XCTestCase { func testDecompressionMultipleWriteWithLimit() { let channel = EmbeddedChannel() - XCTAssertNoThrow(try channel.pipeline.addHandler(NIOHTTPResponseDecompressor(limit: .size(272))).wait()) + XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(NIOHTTPResponseDecompressor(limit: .size(272)))) let headers = HTTPHeaders([("Content-Encoding", "deflate")]) // this compressed payload is 272 bytes long uncompressed @@ -202,7 +202,7 @@ class HTTPResponseDecompressorTest: XCTestCase { func testDecompression() { let channel = EmbeddedChannel() - XCTAssertNoThrow(try channel.pipeline.addHandler(NIOHTTPResponseDecompressor(limit: .none)).wait()) + XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(NIOHTTPResponseDecompressor(limit: .none))) var body = "" for _ in 1...1000 { @@ -266,7 +266,7 @@ class HTTPResponseDecompressorTest: XCTestCase { func testDecompressionWithoutContentLength() { let channel = EmbeddedChannel() - XCTAssertNoThrow(try channel.pipeline.addHandler(NIOHTTPResponseDecompressor(limit: .none)).wait()) + XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(NIOHTTPResponseDecompressor(limit: .none))) var body = "" for _ in 1...1000 { @@ -336,7 +336,7 @@ class HTTPResponseDecompressorTest: XCTestCase { let compressed = ByteBuffer(bytes: [120, 156, 99, 0, 0, 0, 1, 0, 1] + [1, 2, 3]) let channel = EmbeddedChannel() - try channel.pipeline.addHandler(NIOHTTPResponseDecompressor(limit: .none)).wait() + try channel.pipeline.syncOperations.addHandler(NIOHTTPResponseDecompressor(limit: .none)) let headers = HTTPHeaders([("Content-Encoding", "deflate"), ("Content-Length", "\(compressed.readableBytes)")]) try channel.writeInbound( HTTPClientResponsePart.head(.init(version: .init(major: 1, minor: 1), status: .ok, headers: headers)) @@ -350,7 +350,7 @@ class HTTPResponseDecompressorTest: XCTestCase { let compressed = ByteBuffer(bytes: [120, 156, 99, 0]) let channel = EmbeddedChannel() - try channel.pipeline.addHandler(NIOHTTPResponseDecompressor(limit: .none)).wait() + try channel.pipeline.syncOperations.addHandler(NIOHTTPResponseDecompressor(limit: .none)) let headers = HTTPHeaders([("Content-Encoding", "deflate"), ("Content-Length", "\(compressed.readableBytes)")]) try channel.writeInbound( HTTPClientResponsePart.head(.init(version: .init(major: 1, minor: 1), status: .ok, headers: headers)) diff --git a/Tests/NIOSOCKSTests/SOCKSServerHandshakeHandler+Tests.swift b/Tests/NIOSOCKSTests/SOCKSServerHandshakeHandler+Tests.swift index d75366ee..e61d825e 100644 --- a/Tests/NIOSOCKSTests/SOCKSServerHandshakeHandler+Tests.swift +++ b/Tests/NIOSOCKSTests/SOCKSServerHandshakeHandler+Tests.swift @@ -243,7 +243,7 @@ class SOCKSServerHandlerTests: XCTestCase { func testFlushOnHandlerRemoved() { self.writeInbound([0x05, 0x01]) self.assertInbound([]) - XCTAssertNoThrow(try self.channel.pipeline.removeHandler(self.handler).wait()) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.removeHandler(self.handler).wait()) self.assertInbound([0x05, 0x01]) } diff --git a/Tests/NIOSOCKSTests/SocksClientHandler+Tests.swift b/Tests/NIOSOCKSTests/SocksClientHandler+Tests.swift index 5462fdcd..4e8d7e6b 100644 --- a/Tests/NIOSOCKSTests/SocksClientHandler+Tests.swift +++ b/Tests/NIOSOCKSTests/SocksClientHandler+Tests.swift @@ -235,7 +235,7 @@ class SocksClientHandlerTests: XCTestCase { self.assertOutputBuffer([]) // add the handler, there should be outbound data immediately - XCTAssertNoThrow(self.channel.pipeline.addHandler(handler)) + XCTAssertNoThrow(try self.channel.pipeline.syncOperations.addHandler(handler)) self.assertOutputBuffer([0x05, 0x01, 0x00]) } @@ -263,7 +263,7 @@ class SocksClientHandlerTests: XCTestCase { let establishPromise = self.channel.eventLoop.makePromise(of: Void.self) let removalPromise = self.channel.eventLoop.makePromise(of: Void.self) establishPromise.futureResult.whenSuccess { _ in - self.channel.pipeline.removeHandler(self.handler).cascade(to: removalPromise) + self.channel.pipeline.syncOperations.removeHandler(self.handler).cascade(to: removalPromise) } XCTAssertNoThrow( @@ -309,7 +309,7 @@ class SocksClientHandlerTests: XCTestCase { // we try to remove the handler before the connection is established. let removalPromise = self.channel.eventLoop.makePromise(of: Void.self) - self.channel.pipeline.removeHandler(self.handler, promise: removalPromise) + self.channel.pipeline.syncOperations.removeHandler(self.handler, promise: removalPromise) // establishes the connection self.writeInbound([0x05, 0x00, 0x00, 0x01, 192, 168, 1, 1, 0x00, 0x50])