Skip to content

Commit f914380

Browse files
committed
fix merge conflicts
1 parent 1ff9148 commit f914380

8 files changed

+39
-67
lines changed

Sources/AsyncHTTPClient/ConnectionPool/HTTPConnectionPool.swift

+4-15
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ final class HTTPConnectionPool {
9898
case cleanupConnections(CleanupContext, isShutdown: StateMachine.ConnectionAction.IsShutdown)
9999
case migration(
100100
createConnections: [(Connection.ID, EventLoop)],
101-
closeConnections: [Connection],
102-
isShutdown: StateMachine.ConnectionAction.IsShutdown
101+
closeConnections: [Connection]
103102
)
104103
case none
105104
}
@@ -191,16 +190,14 @@ final class HTTPConnectionPool {
191190
case .migration(
192191
let createConnections,
193192
let closeConnections,
194-
let scheduleTimeout,
195-
let isShutdown
193+
let scheduleTimeout
196194
):
197195
if let (connectionID, eventLoop) = scheduleTimeout {
198196
self.locked.connection = .scheduleTimeoutTimer(connectionID, on: eventLoop)
199197
}
200198
self.unlocked.connection = .migration(
201199
createConnections: createConnections,
202-
closeConnections: closeConnections,
203-
isShutdown: isShutdown
200+
closeConnections: closeConnections
204201
)
205202
case .none:
206203
break
@@ -297,11 +294,7 @@ final class HTTPConnectionPool {
297294
self.delegate.connectionPoolDidShutdown(self, unclean: unclean)
298295
}
299296

300-
case .migration(
301-
createConnections: let createConnections,
302-
closeConnections: let closeConnections,
303-
isShutdown: let isShutdown
304-
):
297+
case .migration(let createConnections, let closeConnections):
305298
for connection in closeConnections {
306299
connection.close(promise: nil)
307300
}
@@ -310,10 +303,6 @@ final class HTTPConnectionPool {
310303
self.createConnection(connectionID, on: eventLoop)
311304
}
312305

313-
if case .yes(let unclean) = isShutdown {
314-
self.delegate.connectionPoolDidShutdown(self, unclean: unclean)
315-
}
316-
317306
case .none:
318307
break
319308
}

Sources/AsyncHTTPClient/ConnectionPool/State Machine/HTTPConnectionPool+HTTP1StateMachine.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ extension HTTPConnectionPool {
4949
http2State: HTTP2StateMachine,
5050
newHTTP1Connection: Connection
5151
) -> Action {
52-
self.migrateFromHTTP1(
52+
self.migrateFromHTTP2(
5353
http1Connections: http2State.http1Connections,
5454
http2Connections: http2State.connections,
5555
requests: http2State.requests,
5656
newHTTP1Connection: newHTTP1Connection
5757
)
5858
}
5959

60-
mutating func migrateFromHTTP1(
60+
mutating func migrateFromHTTP2(
6161
http1Connections: HTTP1Connections? = nil,
6262
http2Connections: HTTP2Connections,
6363
requests: RequestQueue,

Sources/AsyncHTTPClient/ConnectionPool/State Machine/HTTPConnectionPool+HTTP2Connections.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ extension HTTPConnectionPool {
351351
/// - Parameters:
352352
/// - starting: starting HTTP connections from previous state machine
353353
/// - backingOff: backing off HTTP connections from previous state machine
354-
mutating func migrateFromHTTP2(
354+
mutating func migrateFromHTTP1(
355355
starting: [(Connection.ID, EventLoop)],
356356
backingOff: [(Connection.ID, EventLoop)]
357357
) {

Sources/AsyncHTTPClient/ConnectionPool/State Machine/HTTPConnectionPool+HTTP2StateMachine.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ extension HTTPConnectionPool {
102102

103103
var http1Connections = http1Connections // make http1Connections mutable
104104
let context = http1Connections.migrateToHTTP2()
105-
self.connections.migrateFromHTTP2(
105+
self.connections.migrateFromHTTP1(
106106
starting: context.starting,
107107
backingOff: context.backingOff
108108
)
@@ -275,7 +275,7 @@ extension HTTPConnectionPool {
275275
}
276276

277277
let connection = self.connections.closeConnection(at: index)
278-
if self.connections.isEmpty {
278+
if self.http1Connections == nil, self.connections.isEmpty {
279279
return .init(
280280
request: .none,
281281
connection: .closeConnection(connection, isShutdown: .yes(unclean: unclean))

Sources/AsyncHTTPClient/ConnectionPool/State Machine/HTTPConnectionPool+StateMachine.swift

+19-26
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ extension HTTPConnectionPool {
4747
case migration(
4848
createConnections: [(Connection.ID, EventLoop)],
4949
closeConnections: [Connection],
50-
scheduleTimeout: (Connection.ID, EventLoop)?,
51-
isShutdown: IsShutdown
50+
scheduleTimeout: (Connection.ID, EventLoop)?
5251
)
5352

5453
case none
@@ -69,23 +68,6 @@ extension HTTPConnectionPool {
6968

7069
enum HTTPVersionState {
7170
case http1(HTTP1StateMachine)
72-
case http2(HTTP2StateMachine)
73-
74-
mutating func modify<ReturnValue>(
75-
http1: (inout HTTP1StateMachine) -> ReturnValue,
76-
http2: (inout HTTP2StateMachine) -> ReturnValue
77-
) -> ReturnValue {
78-
let returnValue: ReturnValue
79-
switch self {
80-
case .http1(var http1State):
81-
returnValue = http1(&http1State)
82-
self = .http1(http1State)
83-
case .http2(var http2State):
84-
returnValue = http2(&http2State)
85-
self = .http2(http2State)
86-
}
87-
return returnValue
88-
}
8971
}
9072

9173
var state: HTTPVersionState
@@ -239,6 +221,10 @@ extension HTTPConnectionPool.StateMachine: CustomStringConvertible {
239221
switch self.state {
240222
case .http1(let http1):
241223
return ".http1(\(http1))"
224+
}
225+
}
226+
}
227+
242228
extension HTTPConnectionPool.StateMachine {
243229
struct ConnectionMigrationAction {
244230
var closeConnections: [HTTPConnectionPool.Connection]
@@ -294,22 +280,29 @@ extension HTTPConnectionPool.StateMachine.ConnectionAction {
294280
return .migration(
295281
createConnections: migrationAction.createConnections,
296282
closeConnections: migrationAction.closeConnections,
297-
scheduleTimeout: nil,
298-
isShutdown: .no
283+
scheduleTimeout: nil
299284
)
300285
case .closeConnection(let connection, let isShutdown):
286+
guard isShutdown == .no else {
287+
precondition(
288+
migrationAction.closeConnections.isEmpty &&
289+
migrationAction.createConnections.isEmpty,
290+
"migration actions are not supported during shutdown"
291+
)
292+
return .closeConnection(connection, isShutdown: isShutdown)
293+
}
294+
var closeConnections = migrationAction.closeConnections
295+
closeConnections.append(connection)
301296
return .migration(
302297
createConnections: migrationAction.createConnections,
303-
closeConnections: migrationAction.closeConnections + CollectionOfOne(connection),
304-
scheduleTimeout: nil,
305-
isShutdown: isShutdown
298+
closeConnections: closeConnections,
299+
scheduleTimeout: nil
306300
)
307301
case .scheduleTimeoutTimer(let connectionID, let eventLoop):
308302
return .migration(
309303
createConnections: migrationAction.createConnections,
310304
closeConnections: migrationAction.closeConnections,
311-
scheduleTimeout: (connectionID, eventLoop),
312-
isShutdown: .no
305+
scheduleTimeout: (connectionID, eventLoop)
313306
)
314307
}
315308
}

Tests/AsyncHTTPClientTests/HTTPConnectionPool+HTTP2ConnectionsTest.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ class HTTPConnectionPool_HTTP2ConnectionsTests: XCTestCase {
513513
let conn1ID: HTTPConnectionPool.Connection.ID = 1
514514
let conn2ID: HTTPConnectionPool.Connection.ID = 2
515515

516-
connections.migrateFromHTTP2(
516+
connections.migrateFromHTTP1(
517517
starting: [(conn1ID, el1)],
518518
backingOff: [(conn2ID, el2)]
519519
)

Tests/AsyncHTTPClientTests/HTTPConnectionPool+HTTP2StateMachineTests.swift

+7-13
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ class HTTPConnectionPool_HTTP2StateMachineTests: XCTestCase {
313313
var http2State = HTTPConnectionPool.HTTP2StateMachine(idGenerator: idGenerator)
314314

315315
let http2ConnectAction = http2State.migrateFromHTTP1(http1State: http1State, newHTTP2Connection: conn2, maxConcurrentStreams: 100)
316-
XCTAssertEqual(http2ConnectAction.connection, .migration(createConnections: [], closeConnections: [], scheduleTimeout: nil, isShutdown: .no))
316+
XCTAssertEqual(http2ConnectAction.connection, .migration(createConnections: [], closeConnections: [], scheduleTimeout: nil))
317317
guard case .executeRequestsAndCancelTimeouts([request2], conn2) = http2ConnectAction.request else {
318318
return XCTFail("Unexpected request action \(http2ConnectAction.request)")
319319
}
@@ -353,8 +353,7 @@ class HTTPConnectionPool_HTTP2StateMachineTests: XCTestCase {
353353
XCTAssertEqual(connectAction.connection, .migration(
354354
createConnections: [],
355355
closeConnections: [],
356-
scheduleTimeout: (conn1ID, el1),
357-
isShutdown: .no
356+
scheduleTimeout: (conn1ID, el1)
358357
))
359358

360359
// execute request on idle connection
@@ -398,8 +397,7 @@ class HTTPConnectionPool_HTTP2StateMachineTests: XCTestCase {
398397
XCTAssertEqual(connectAction.connection, .migration(
399398
createConnections: [],
400399
closeConnections: [],
401-
scheduleTimeout: (conn1ID, el1),
402-
isShutdown: .no
400+
scheduleTimeout: (conn1ID, el1)
403401
))
404402

405403
// let the connection timeout
@@ -426,8 +424,7 @@ class HTTPConnectionPool_HTTP2StateMachineTests: XCTestCase {
426424
XCTAssertEqual(connectAction.connection, .migration(
427425
createConnections: [],
428426
closeConnections: [],
429-
scheduleTimeout: (conn1ID, el1),
430-
isShutdown: .no
427+
scheduleTimeout: (conn1ID, el1)
431428
))
432429

433430
// create new http2 connection
@@ -469,8 +466,7 @@ class HTTPConnectionPool_HTTP2StateMachineTests: XCTestCase {
469466
XCTAssertEqual(connectAction.connection, .migration(
470467
createConnections: [],
471468
closeConnections: [],
472-
scheduleTimeout: (conn1ID, el1),
473-
isShutdown: .no
469+
scheduleTimeout: (conn1ID, el1)
474470
))
475471

476472
let goAwayAction = state.http2ConnectionGoAwayReceived(conn1ID)
@@ -499,8 +495,7 @@ class HTTPConnectionPool_HTTP2StateMachineTests: XCTestCase {
499495
XCTAssertEqual(connectAction.connection, .migration(
500496
createConnections: [],
501497
closeConnections: [],
502-
scheduleTimeout: (conn1ID, el1),
503-
isShutdown: .no
498+
scheduleTimeout: (conn1ID, el1)
504499
))
505500

506501
// execute request on idle connection
@@ -541,8 +536,7 @@ class HTTPConnectionPool_HTTP2StateMachineTests: XCTestCase {
541536
XCTAssertEqual(connectAction1.connection, .migration(
542537
createConnections: [],
543538
closeConnections: [],
544-
scheduleTimeout: (conn1ID, el1),
545-
isShutdown: .no
539+
scheduleTimeout: (conn1ID, el1)
546540
))
547541

548542
// execute request

Tests/AsyncHTTPClientTests/HTTPConnectionPool+StateTestUtils.swift

+3-7
Original file line numberDiff line numberDiff line change
@@ -91,24 +91,20 @@ extension HTTPConnectionPool.StateMachine.ConnectionAction: Equatable {
9191
.migration(
9292
let lhsCreateConnections,
9393
let lhsCloseConnections,
94-
let lhsScheduleTimeout,
95-
let lhsIsShutdown
94+
let lhsScheduleTimeout
9695
),
9796
.migration(
9897
let rhsCreateConnections,
9998
let rhsCloseConnections,
100-
let rhsScheduleTimeout,
101-
let rhsIsShutdown
99+
let rhsScheduleTimeout
102100
)
103101
):
104102
return lhsCreateConnections.elementsEqual(rhsCreateConnections, by: {
105103
$0.0 == $1.0 && $0.1 === $1.1
106104
}) &&
107105
lhsCloseConnections == rhsCloseConnections &&
108106
lhsScheduleTimeout?.0 == rhsScheduleTimeout?.0 &&
109-
lhsScheduleTimeout?.1 === rhsScheduleTimeout?.1 &&
110-
lhsIsShutdown == rhsIsShutdown
111-
107+
lhsScheduleTimeout?.1 === rhsScheduleTimeout?.1
112108
case (.none, .none):
113109
return true
114110
default:

0 commit comments

Comments
 (0)