@@ -4307,7 +4307,41 @@ final class HTTPClientTests: XCTestCaseHTTPClientTestsBaseClass {
43074307 XCTAssertEqual ( request. headers. first ( name: " Authorization " ) , " Basic Zm9vOmJhcg== " )
43084308 }
43094309
4310- func testHTTP1ConnectionDebugInitializer( ) {
4310+ func testHTTP1PlainTextConnectionDebugInitializer( ) {
4311+ let connectionDebugInitializerUtil = CountingDebugInitializerUtil ( )
4312+
4313+ // Initializing even with just `http1_1ConnectionDebugInitializer` (rather than manually
4314+ // modifying `config`) to ensure that the matching `init` actually wires up this argument
4315+ // with the respective property. This is necessary as these parameters are defaulted and can
4316+ // be easy to miss.
4317+ var config = HTTPClient . Configuration (
4318+ http1_1ConnectionDebugInitializer: connectionDebugInitializerUtil. initialize ( channel: )
4319+ )
4320+ config. httpVersion = . http1Only
4321+
4322+ let client = HTTPClient (
4323+ eventLoopGroupProvider: . singleton,
4324+ configuration: config,
4325+ backgroundActivityLogger: Logger (
4326+ label: " HTTPClient " ,
4327+ factory: StreamLogHandler . standardOutput ( label: )
4328+ )
4329+ )
4330+ defer { XCTAssertNoThrow ( client. shutdown ( ) ) }
4331+
4332+ let bin = HTTPBin ( . http1_1( ssl: false , compress: false ) )
4333+ defer { XCTAssertNoThrow ( try bin. shutdown ( ) ) }
4334+
4335+ for _ in 0 ..< 3 {
4336+ XCTAssertNoThrow ( try client. get ( url: " http://localhost: \( bin. port) /get " ) . wait ( ) )
4337+ }
4338+
4339+ // Even though multiple requests were made, the connection debug initializer must be called
4340+ // only once.
4341+ XCTAssertEqual ( connectionDebugInitializerUtil. executionCount, 1 )
4342+ }
4343+
4344+ func testHTTP1EncryptedConnectionDebugInitializer( ) {
43114345 let connectionDebugInitializerUtil = CountingDebugInitializerUtil ( )
43124346
43134347 // Initializing even with just `http1_1ConnectionDebugInitializer` (rather than manually
@@ -4340,7 +4374,7 @@ final class HTTPClientTests: XCTestCaseHTTPClientTestsBaseClass {
43404374
43414375 // Even though multiple requests were made, the connection debug initializer must be called
43424376 // only once.
4343- XCTAssertEqual ( connectionDebugInitializerUtil. executionCount. withLockedValue { $0 } , 1 )
4377+ XCTAssertEqual ( connectionDebugInitializerUtil. executionCount, 1 )
43444378 }
43454379
43464380 func testHTTP2ConnectionAndStreamChannelDebugInitializers( ) {
@@ -4382,32 +4416,27 @@ final class HTTPClientTests: XCTestCaseHTTPClientTestsBaseClass {
43824416
43834417 // Even though multiple requests were made, the connection debug initializer must be called
43844418 // only once.
4385- XCTAssertEqual (
4386- connectionDebugInitializerUtil. executionCount. withLockedValue { $0 } ,
4387- 1
4388- )
4419+ XCTAssertEqual ( connectionDebugInitializerUtil. executionCount, 1 )
43894420
43904421 // The stream channel debug initializer must be called only as much as the number of
43914422 // requests made.
4392- XCTAssertEqual (
4393- streamChannelDebugInitializerUtil. executionCount. withLockedValue { $0 } ,
4394- numberOfRequests
4395- )
4423+ XCTAssertEqual ( streamChannelDebugInitializerUtil. executionCount, numberOfRequests)
43964424 }
43974425}
43984426
43994427final class CountingDebugInitializerUtil : Sendable {
4400- let executionCount : NIOLockedValueBox < Int >
4428+ private let _executionCount : NIOLockedValueBox < Int >
4429+ var executionCount : Int { self . _executionCount. withLockedValue { $0 } }
44014430
44024431 /// The acual debug initializer.
44034432 @Sendable
44044433 func initialize( channel: Channel ) -> EventLoopFuture < Void > {
4405- self . executionCount . withLockedValue { $0 += 1 }
4434+ self . _executionCount . withLockedValue { $0 += 1 }
44064435
44074436 return channel. eventLoop. makeSucceededVoidFuture ( )
44084437 }
44094438
44104439 init ( ) {
4411- self . executionCount = . init( 0 )
4440+ self . _executionCount = . init( 0 )
44124441 }
44134442}
0 commit comments