@@ -680,40 +680,21 @@ class HTTPConnectionPool_HTTP2StateMachineTests: XCTestCase {
680
680
var queuer = MockRequestQueuer ( )
681
681
var state = HTTPConnectionPool . StateMachine ( idGenerator: . init( ) , maximumConcurrentHTTP1Connections: 8 )
682
682
683
- /// first 8 request should create a new connection
684
- var connectionIDs : [ HTTPConnectionPool . Connection . ID ] = [ ]
685
- for _ in 0 ..< 8 {
686
- let mockRequest = MockHTTPRequest ( eventLoop: el1)
687
- let request = HTTPConnectionPool . Request ( mockRequest)
688
- let action = state. executeRequest ( request)
689
- guard case . createConnection( let connID, let eventLoop) = action. connection else {
690
- return XCTFail ( " Unexpected connection action \( action. connection) " )
691
- }
692
- connectionIDs. append ( connID)
693
- XCTAssertTrue ( eventLoop === el1)
694
- XCTAssertEqual ( action. request, . scheduleRequestTimeout( for: request, on: mockRequest. eventLoop) )
695
- XCTAssertNoThrow ( try connections. createConnection ( connID, on: el1) )
696
- XCTAssertNoThrow ( try queuer. queue ( mockRequest, id: request. id) )
697
- }
698
-
699
- guard let conn1ID = connectionIDs. first else {
700
- return XCTFail ( " could not create connection " )
701
- }
702
-
703
- /// after we reached the `maximumConcurrentHTTP1Connections`, we will not create new connections
704
- for _ in 0 ..< 8 {
705
- let mockRequest = MockHTTPRequest ( eventLoop: el1)
706
- let request = HTTPConnectionPool . Request ( mockRequest)
707
- let action = state. executeRequest ( request)
708
- XCTAssertEqual ( action. connection, . none)
709
- XCTAssertEqual ( action. request, . scheduleRequestTimeout( for: request, on: mockRequest. eventLoop) )
710
-
711
- XCTAssertNoThrow ( try queuer. queue ( mockRequest, id: request. id) )
683
+ /// create a new connection
684
+ let mockRequest = MockHTTPRequest ( eventLoop: el1)
685
+ let request = HTTPConnectionPool . Request ( mockRequest)
686
+ let action = state. executeRequest ( request)
687
+ guard case . createConnection( let conn1ID, let eventLoop) = action. connection else {
688
+ return XCTFail ( " Unexpected connection action \( action. connection) " )
712
689
}
690
+
691
+ XCTAssertTrue ( eventLoop === el1)
692
+ XCTAssertEqual ( action. request, . scheduleRequestTimeout( for: request, on: mockRequest. eventLoop) )
693
+ XCTAssertNoThrow ( try connections. createConnection ( conn1ID, on: el1) )
694
+ XCTAssertNoThrow ( try queuer. queue ( mockRequest, id: request. id) )
713
695
714
696
/// we now no longer want anything of it
715
697
let shutdownAction = state. shutdown ( )
716
-
717
698
guard case . failRequestsAndCancelTimeouts( let requestsToCancel, let error) = shutdownAction. request else {
718
699
return XCTFail ( " unexpected shutdown action \( shutdownAction) " )
719
700
}
@@ -725,34 +706,13 @@ class HTTPConnectionPool_HTTP2StateMachineTests: XCTestCase {
725
706
}
726
707
XCTAssertTrue ( queuer. isEmpty)
727
708
728
- /// first new HTTP2 connection should migrate from HTTP1 to HTTP2 and execute requests
709
+ /// new HTTP2 connection should migrate from HTTP1 to HTTP2, close the connection and shutdown the pool
729
710
let conn1 : HTTPConnectionPool . Connection = . __testOnly_connection( id: conn1ID, eventLoop: el1)
730
711
XCTAssertNoThrow ( try connections. succeedConnectionCreationHTTP2 ( conn1ID, maxConcurrentStreams: 10 ) )
731
712
let migrationAction = state. newHTTP2ConnectionCreated ( conn1, maxConcurrentStreams: 10 )
732
713
XCTAssertEqual ( migrationAction. request, . none)
733
- XCTAssertEqual ( migrationAction. connection, . migration(
734
- createConnections: [ ] ,
735
- closeConnections: [ conn1] ,
736
- scheduleTimeout: nil
737
- ) )
714
+ XCTAssertEqual ( migrationAction. connection, . closeConnection( conn1, isShutdown: . yes( unclean: true ) ) )
738
715
XCTAssertNoThrow ( try connections. closeConnection ( conn1) )
739
-
740
- /// remaining connections should be closed immediately without executing any request
741
- for connID in connectionIDs. dropFirst ( ) . dropLast ( ) {
742
- let conn : HTTPConnectionPool . Connection = . __testOnly_connection( id: connID, eventLoop: el1)
743
- XCTAssertNoThrow ( try connections. succeedConnectionCreationHTTP2 ( connID, maxConcurrentStreams: 10 ) )
744
- let action = state. newHTTP2ConnectionCreated ( conn, maxConcurrentStreams: 10 )
745
- XCTAssertEqual ( action. request, . none)
746
- XCTAssertEqual ( action. connection, . closeConnection( conn, isShutdown: . no) )
747
- XCTAssertNoThrow ( try connections. closeConnection ( conn) )
748
- }
749
- let lastConnID = connectionIDs. last!
750
- let lastConn : HTTPConnectionPool . Connection = . __testOnly_connection( id: lastConnID, eventLoop: el1)
751
- XCTAssertNoThrow ( try connections. succeedConnectionCreationHTTP2 ( lastConnID, maxConcurrentStreams: 10 ) )
752
- let action = state. newHTTP2ConnectionCreated ( lastConn, maxConcurrentStreams: 10 )
753
- XCTAssertEqual ( action. request, . none)
754
- XCTAssertEqual ( action. connection, . closeConnection( lastConn, isShutdown: . yes( unclean: true ) ) )
755
- XCTAssertNoThrow ( try connections. closeConnection ( lastConn) )
756
716
XCTAssertTrue ( connections. isEmpty)
757
717
}
758
718
0 commit comments