diff --git a/Tests/NIOTransportServicesTests/NIOTSBootstrapTests.swift b/Tests/NIOTransportServicesTests/NIOTSBootstrapTests.swift index 33c0bd0..c6242cc 100644 --- a/Tests/NIOTransportServicesTests/NIOTSBootstrapTests.swift +++ b/Tests/NIOTransportServicesTests/NIOTSBootstrapTests.swift @@ -371,6 +371,36 @@ final class NIOTSBootstrapTests: XCTestCase { XCTAssertEqual(try listenerChannel.getOption(NIOTSChannelOptions.multipathServiceType).wait(), .handover) XCTAssertEqual(try connectionChannel.getOption(NIOTSChannelOptions.multipathServiceType).wait(), .handover) } + + func testNWParametersConfigurator() throws { + let group = NIOTSEventLoopGroup() + defer { + try! group.syncShutdownGracefully() + } + + let configuratorListenerCounter = NIOLockedValueBox(0) + let configuratorConnectionCounter = NIOLockedValueBox(0) + + let listenerChannel = try NIOTSListenerBootstrap(group: group) + .configureNWParameters { _ in + configuratorListenerCounter.withLockedValue { $0 += 1 } + } + .bind(host: "localhost", port: 0) + .wait() + + let connectionChannel: Channel = try NIOTSConnectionBootstrap(group: group) + .configureNWParameters { _ in + configuratorConnectionCounter.withLockedValue { $0 += 1 } + } + .connect(to: listenerChannel.localAddress!) + .wait() + + try listenerChannel.close().wait() + try connectionChannel.close().wait() + + XCTAssertEqual(1, configuratorListenerCounter.withLockedValue { $0 }) + XCTAssertEqual(1, configuratorConnectionCounter.withLockedValue { $0 }) + } } extension Channel { diff --git a/Tests/NIOTransportServicesTests/NIOTSDatagramConnectionChannelTests.swift b/Tests/NIOTransportServicesTests/NIOTSDatagramConnectionChannelTests.swift index 9b74395..b9f8b2f 100644 --- a/Tests/NIOTransportServicesTests/NIOTSDatagramConnectionChannelTests.swift +++ b/Tests/NIOTransportServicesTests/NIOTSDatagramConnectionChannelTests.swift @@ -18,6 +18,7 @@ import Network import NIOCore import NIOTransportServices import Foundation +import NIOConcurrencyHelpers extension Channel { func wait(for type: T.Type, count: Int) throws -> [T] { @@ -232,6 +233,36 @@ final class NIOTSDatagramConnectionChannelTests: XCTestCase { XCTAssertNoThrow(try connection.close().wait()) } + func testNWParametersConfigurator() throws { + let group = NIOTSEventLoopGroup() + defer { + try! group.syncShutdownGracefully() + } + + let configuratorListenerCounter = NIOLockedValueBox(0) + let configuratorConnectionCounter = NIOLockedValueBox(0) + + let listenerChannel = try NIOTSDatagramListenerBootstrap(group: group) + .configureNWParameters { _ in + configuratorListenerCounter.withLockedValue { $0 += 1 } + } + .bind(host: "localhost", port: 0) + .wait() + + let connectionChannel: Channel = try NIOTSDatagramBootstrap(group: group) + .configureNWParameters { _ in + configuratorConnectionCounter.withLockedValue { $0 += 1 } + } + .connect(to: listenerChannel.localAddress!) + .wait() + + try listenerChannel.close().wait() + try connectionChannel.close().wait() + + XCTAssertEqual(1, configuratorListenerCounter.withLockedValue { $0 }) + XCTAssertEqual(1, configuratorConnectionCounter.withLockedValue { $0 }) + } + func testCanExtractTheConnection() throws { guard #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) else { throw XCTSkip("Option not available")