@@ -1421,49 +1421,49 @@ extension ConnectionManagerTests {
1421
1421
1422
1422
#if canImport(Network)
1423
1423
func testDefaultChannelProvider_NWParametersConfigurator( ) throws {
1424
+ // For this test, we want an actual connection to be established, since otherwise the parameters
1425
+ // configurator won't be run: NIOTS will only apply the parameters on the NWConnection at the
1426
+ // point of activating it.
1427
+
1428
+ // Start a server
1429
+ let serverConfig = Server . Configuration. default (
1430
+ target: . hostAndPort( " localhost " , 0 ) ,
1431
+ eventLoopGroup: NIOTSEventLoopGroup . singleton,
1432
+ serviceProviders: [ ]
1433
+ )
1434
+ let server = try Server . start ( configuration: serverConfig) . wait ( )
1435
+ defer {
1436
+ try ? server. close ( ) . wait ( )
1437
+ }
1438
+
1439
+ // Create a connection manager, and configure it to increase a counter in its NWParameters
1440
+ // configurator closure.
1424
1441
let counter = NIOLockedValueBox ( 0 )
1425
1442
let group = NIOTSEventLoopGroup . singleton
1426
1443
var configuration = ClientConnection . Configuration. default (
1427
- target: . unixDomainSocket ( " /ignored " ) ,
1444
+ target: . socketAddress ( server . channel . localAddress! ) ,
1428
1445
eventLoopGroup: group
1429
1446
)
1430
1447
configuration. nwParametersConfigurator = { _ in
1431
1448
counter. withLockedValue { $0 += 1 }
1432
1449
}
1433
-
1434
- // We need to trigger the connection to apply the parameters configurator.
1435
- // However, we don't actually care about establishing the connection: only triggering it.
1436
- // In other tests, we used mocked channel providers to simply return completed futures when "creating"
1437
- // the channels. However, in this test we want to make sure that the `DefaultChannelProvider`,
1438
- // which is the one we actually use, correctly sets and executes the configurator.
1439
- // For this reason, we can wait on a promise that is succeeded after the configurator has been called,
1440
- // in the debug channel initializer. This promise will always succeed regardless of the actual
1441
- // connection being established. And because this closure is executed after the parameters configurator,
1442
- // we know the counter should be updated by the time the promise has been completed.
1443
- let promise = group. next ( ) . makePromise ( of: Void . self)
1444
- configuration. debugChannelInitializer = { channel in
1445
- promise. succeed ( )
1446
- return promise. futureResult
1447
- }
1448
-
1449
1450
let manager = ConnectionManager (
1450
1451
configuration: configuration,
1451
1452
connectivityDelegate: self . monitor,
1452
1453
idleBehavior: . closeWhenIdleTimeout,
1453
1454
logger: self . logger
1454
1455
)
1456
+ defer {
1457
+ try ? manager. shutdown ( ) . wait ( )
1458
+ }
1455
1459
1456
- // Start connecting. We don't care about the actual result of the connection.
1457
- _ = manager. getHTTP2Multiplexer ( )
1458
-
1459
- // Wait until the configurator has been called.
1460
- try promise. futureResult. wait ( )
1460
+ // Wait for the connection to be established.
1461
+ _ = try manager. getHTTP2Multiplexer ( ) . wait ( )
1461
1462
1463
+ // At this point, the configurator must have been called.
1462
1464
XCTAssertEqual ( 1 , counter. withLockedValue ( { $0 } ) )
1463
1465
}
1464
1466
#endif
1465
-
1466
- // TODO: add test using the default channel provider that uses the parameter configurator and make sure it gets called
1467
1467
}
1468
1468
1469
1469
internal struct Change : Hashable , CustomStringConvertible {
0 commit comments