Add tests

This commit is contained in:
Gus Cairo 2025-04-09 14:43:16 +01:00
parent b37cc8bd40
commit 7a8dcde582
2 changed files with 61 additions and 0 deletions

View File

@ -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 {

View File

@ -18,6 +18,7 @@ import Network
import NIOCore
import NIOTransportServices
import Foundation
import NIOConcurrencyHelpers
extension Channel {
func wait<T: Sendable>(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")