Repository: apple/swift-nio
File: Tests/NIOTestUtilsTests/NIOHTTP1TestServerTest.swift (Swift)

Code before:
    typealias OutboundOut = HTTPClientRequestPart

    func write(context: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?) {
        let response = self.unwrapOutboundIn(data)
        context.write(self.wrapOutboundOut(.init(response)), promise: nil)
    }
}

class NIOHTTP1TestServerTest: XCTestCase {
    private var group: EventLoopGroup!
    private let allocator = ByteBufferAllocator()

    override func setUp() {
        self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
    }

    override func tearDown() {
        XCTAssertNoThrow(try self.group.syncShutdownGracefully())
        self.group = nil
    }

    func connect(serverPort: Int, responsePromise: EventLoopPromise<String>) throws -> EventLoopFuture<Channel> {
        let bootstrap = ClientBootstrap(group: self.group)
            .channelOption(.socketOption(.so_reuseaddr), value: 1)
            .channelInitializer { channel in
                return channel.eventLoop.makeCompletedFuture {
                    let sync = channel.pipeline.syncOperations
                    try sync.addHTTPClientHandlers(position: .first, leftOverBytesStrategy: .fireError)
                    try sync.addHandler(AggregateBodyHandler())
                    try sync.addHandler(TestHTTPHandler(responsePromise: responsePromise))
                    try sync.addHandler(TransformerHandler())
                }
            }
        return bootstrap.connect(host: "127.0.0.1", port: serverPort)
    }

    private func sendRequest(channel: Channel, uri: String, message: String) {
        let requestBuffer = allocator.buffer(string: message)
        var headers = HTTPHeaders()
        headers.add(name: "Content-Type", value: "text/plain; charset=utf-8")
        headers.add(name: "Content-Length", value: "\(requestBuffer.readableBytes)")

        let requestHead = HTTPRequestHead(
            version: .http1_1,
            method: .GET,
            uri: uri,
            headers: headers
        )

        channel.write(SendableRequestPart.head(requestHead), promise: nil)
        channel.write(SendableRequestPart.body(requestBuffer), promise: nil)

Review comment (suggestion):
```suggestion
                channel.eventLoop.makeCompletedFuture {
```

Code after:
    typealias OutboundOut = HTTPClientRequestPart

    func write(context: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?) {
        let response = self.unwrapOutboundIn(data)
        context.write(self.wrapOutboundOut(.init(response)), promise: nil)
    }
}

class NIOHTTP1TestServerTest: XCTestCase {
    private var group: EventLoopGroup!
    private let allocator = ByteBufferAllocator()

    override func setUp() {
        self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
    }

    override func tearDown() {
        XCTAssertNoThrow(try self.group.syncShutdownGracefully())
        self.group = nil
    }

    func connect(serverPort: Int, responsePromise: EventLoopPromise<String>) throws -> EventLoopFuture<Channel> {
        let bootstrap = ClientBootstrap(group: self.group)
            .channelOption(.socketOption(.so_reuseaddr), value: 1)
            .channelInitializer { channel in
                channel.eventLoop.makeCompletedFuture {
                    let sync = channel.pipeline.syncOperations
                    try sync.addHTTPClientHandlers(position: .first, leftOverBytesStrategy: .fireError)
                    try sync.addHandler(AggregateBodyHandler())
                    try sync.addHandler(TestHTTPHandler(responsePromise: responsePromise))
                    try sync.addHandler(TransformerHandler())
                }
            }
        return bootstrap.connect(host: "127.0.0.1", port: serverPort)
    }

    private func sendRequest(channel: Channel, uri: String, message: String) {
        let requestBuffer = allocator.buffer(string: message)
        var headers = HTTPHeaders()
        headers.add(name: "Content-Type", value: "text/plain; charset=utf-8")
        headers.add(name: "Content-Length", value: "\(requestBuffer.readableBytes)")

        let requestHead = HTTPRequestHead(
            version: .http1_1,
            method: .GET,
            uri: uri,
            headers: headers
        )

        channel.write(SendableRequestPart.head(requestHead), promise: nil)
        channel.write(SendableRequestPart.body(requestBuffer), promise: nil)