Repository: apple/swift-nio
File: Tests/NIOPosixTests/ChannelTests.swift (Swift)

Code before:
                    promise?.fail(DummyError())
                } else {
                    context.close(mode: mode, promise: promise)
                }
            }
        }

        let channel = try! assertNoThrowWithValue(ServerBootstrap(group: group).serverChannelInitializer { channel in
            channel.pipeline.addHandler(MakeFirstCloseFailAndDontActuallyCloseHandler(), position: .first)
        }.bind(host: "localhost", port: 0).wait())
        defer {
            XCTAssertNoThrow(try channel.close().wait())
        }

        XCTAssertNoThrow(try channel.pipeline.addHandler(counter).wait())

        XCTAssertNoThrow(try channel.eventLoop.submit {
            // this will trigger a close (which will fail and also not actually close)
            channel.pipeline.fireUserInboundEventTriggered(ChannelShouldQuiesceEvent())
        }.wait())
        XCTAssertEqual(["userInboundEventTriggered", "close", "errorCaught"], counter.allTriggeredEvents())
        XCTAssertEqual(1, counter.errorCaughtCalls)
    }

    func _testTCP_NODELAYis(
        enabledByDefault: Bool,
        for socketAddress: SocketAddress,
        file: StaticString = #file,
        line: UInt = #line
    ) throws {
        let singleThreadedELG = MultiThreadedEventLoopGroup(numberOfThreads: 1)
        defer {
            XCTAssertNoThrow(try singleThreadedELG.syncShutdownGracefully(), file: file, line: line)
        }
        let acceptedChannel = singleThreadedELG.next().makePromise(of: Channel.self)
        let server = try assertNoThrowWithValue(
            ServerBootstrap(group: singleThreadedELG)
            .childChannelInitializer { channel in
                acceptedChannel.succeed(channel)
                return channel.eventLoop.makeSucceededFuture(())
            }
            .bind(to: socketAddress)
            .wait(),
            file: file, line: line
        )
        defer {
            XCTAssertNoThrow(try server.close().wait(), file: file, line: line)
        }

        let client = try assertNoThrowWithValue(
            ClientBootstrap(group: singleThreadedELG)

Review comment (suggestion):
This kind of "narrative style" function name is discouraged in Swift APIs, and in this particular instance I think it's hard to read. I think it'd be better to rename this to `_testTCP_NODELAYDefaultValue(value:`

Code after:
                    promise?.fail(DummyError())
                } else {
                    context.close(mode: mode, promise: promise)
                }
            }
        }

        let channel = try! assertNoThrowWithValue(ServerBootstrap(group: group).serverChannelInitializer { channel in
            channel.pipeline.addHandler(MakeFirstCloseFailAndDontActuallyCloseHandler(), position: .first)
        }.bind(host: "localhost", port: 0).wait())
        defer {
            XCTAssertNoThrow(try channel.close().wait())
        }

        XCTAssertNoThrow(try channel.pipeline.addHandler(counter).wait())

        XCTAssertNoThrow(try channel.eventLoop.submit {
            // this will trigger a close (which will fail and also not actually close)
            channel.pipeline.fireUserInboundEventTriggered(ChannelShouldQuiesceEvent())
        }.wait())
        XCTAssertEqual(["userInboundEventTriggered", "close", "errorCaught"], counter.allTriggeredEvents())
        XCTAssertEqual(1, counter.errorCaughtCalls)
    }

    func _testTCP_NODELAYDefaultValue(
        value: Bool,
        _ socketAddress: SocketAddress,
        file: StaticString = #file,
        line: UInt = #line
    ) throws {
        let singleThreadedELG = MultiThreadedEventLoopGroup(numberOfThreads: 1)
        defer {
            XCTAssertNoThrow(try singleThreadedELG.syncShutdownGracefully(), file: file, line: line)
        }
        let acceptedChannel = singleThreadedELG.next().makePromise(of: Channel.self)
        let server = try assertNoThrowWithValue(
            ServerBootstrap(group: singleThreadedELG)
            .childChannelInitializer { channel in
                acceptedChannel.succeed(channel)
                return channel.eventLoop.makeSucceededFuture(())
            }
            .bind(to: socketAddress)
            .wait(),
            file: file, line: line
        )
        defer {
            XCTAssertNoThrow(try server.close().wait(), file: file, line: line)
        }

        let client = try assertNoThrowWithValue(
            ClientBootstrap(group: singleThreadedELG)