@@ -1493,4 +1493,35 @@ class HTTPConnectionPool_HTTP1StateMachineTests: XCTestCase {
14931493
14941494 // We won't bother doing it though, it's enough that it asked.
14951495 }
1496+
1497+ func testFailConnectionRacesAgainstConnectionCreationFailed( ) {
1498+ let elg = EmbeddedEventLoopGroup ( loops: 4 )
1499+ defer { XCTAssertNoThrow ( try elg. syncShutdownGracefully ( ) ) }
1500+
1501+ var state = HTTPConnectionPool . StateMachine (
1502+ idGenerator: . init( ) ,
1503+ maximumConcurrentHTTP1Connections: 2 ,
1504+ retryConnectionEstablishment: true ,
1505+ preferHTTP1: true ,
1506+ maximumConnectionUses: nil ,
1507+ preWarmedHTTP1ConnectionCount: 0
1508+ )
1509+
1510+ let mockRequest = MockHTTPScheduableRequest ( eventLoop: elg. next ( ) )
1511+ let request = HTTPConnectionPool . Request ( mockRequest)
1512+
1513+ let executeAction = state. executeRequest ( request)
1514+ XCTAssertEqual ( . scheduleRequestTimeout( for: request, on: mockRequest. eventLoop) , executeAction. request)
1515+
1516+ // 1. connection attempt
1517+ guard case . createConnection( let connectionID, on: let connectionEL) = executeAction. connection else {
1518+ return XCTFail ( " Unexpected connection action: \( executeAction. connection) " )
1519+ }
1520+ XCTAssert ( connectionEL === mockRequest. eventLoop) // XCTAssertIdentical not available on Linux
1521+
1522+ // 2. connection fails
1523+
1524+ state. http1ConnectionClosed ( connectionID)
1525+ state. failedToCreateNewConnection ( IOError ( errnoCode: - 1 , reason: " Test failure " ) , connectionID: connectionID)
1526+ }
14961527}
0 commit comments