Skip to content

Commit 2bededd

Browse files
committed
Fix tests?!
1 parent dd41068 commit 2bededd

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ extension HTTPConnectionPool {
250250
self.failedConsecutiveConnectionAttempts += 1
251251
self.lastConnectFailure = error
252252

253+
// We don't care how many waiting requests we have at this point, we will schedule a
254+
// retry. More tasks, may appear until the backoff has completed. The final
255+
// decision about the retry will be made in `connectionCreationBackoffDone(_:)`
256+
let eventLoop = self.connections.backoffNextConnectionAttempt(connectionID)
257+
253258
switch self.lifecycleState {
254259
case .running:
255260
guard self.retryConnectionEstablishment else {
@@ -265,10 +270,6 @@ extension HTTPConnectionPool {
265270
connection: .none
266271
)
267272
}
268-
// We don't care how many waiting requests we have at this point, we will schedule a
269-
// retry. More tasks, may appear until the backoff has completed. The final
270-
// decision about the retry will be made in `connectionCreationBackoffDone(_:)`
271-
let eventLoop = self.connections.backoffNextConnectionAttempt(connectionID)
272273

273274
let backoff = calculateBackoff(failedAttempt: self.failedConsecutiveConnectionAttempts)
274275
return .init(

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -226,20 +226,18 @@ extension HTTPConnectionPool {
226226
) -> EstablishedAction {
227227
self.failedConsecutiveConnectionAttempts = 0
228228
self.lastConnectFailure = nil
229-
if self.connections.hasActiveConnection(for: connection.eventLoop) {
230-
guard let (index, _) = self.connections.failConnection(connection.id) else {
231-
preconditionFailure("we have established a new connection that we know nothing about?")
232-
}
233-
self.connections.removeConnection(at: index)
229+
let doesConnectionExistsForEL = self.connections.hasActiveConnection(for: connection.eventLoop)
230+
let (index, context) = self.connections.newHTTP2ConnectionEstablished(
231+
connection,
232+
maxConcurrentStreams: maxConcurrentStreams
233+
)
234+
if doesConnectionExistsForEL {
235+
let connection = self.connections.closeConnection(at: index)
234236
return .init(
235237
request: .none,
236238
connection: .closeConnection(connection, isShutdown: .no)
237239
)
238240
} else {
239-
let (index, context) = self.connections.newHTTP2ConnectionEstablished(
240-
connection,
241-
maxConcurrentStreams: maxConcurrentStreams
242-
)
243241
return self.nextActionForAvailableConnection(at: index, context: context)
244242
}
245243
}
@@ -424,6 +422,8 @@ extension HTTPConnectionPool {
424422
self.failedConsecutiveConnectionAttempts += 1
425423
self.lastConnectFailure = error
426424

425+
let eventLoop = self.connections.backoffNextConnectionAttempt(connectionID)
426+
427427
switch self.lifecycleState {
428428
case .running:
429429
guard self.retryConnectionEstablishment else {
@@ -440,7 +440,6 @@ extension HTTPConnectionPool {
440440
)
441441
}
442442

443-
let eventLoop = self.connections.backoffNextConnectionAttempt(connectionID)
444443
let backoff = calculateBackoff(failedAttempt: self.failedConsecutiveConnectionAttempts)
445444
return .init(
446445
request: .none,

Tests/AsyncHTTPClientTests/HTTPConnectionPool+HTTP1ConnectionsTest.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ class HTTPConnectionPool_HTTP1ConnectionsTests: XCTestCase {
384384
XCTAssertEqual(connections.closeConnection(at: releaseIndex), lease)
385385
XCTAssertFalse(connections.isEmpty)
386386

387+
let backoffEL = connections.backoffNextConnectionAttempt(startingID)
388+
XCTAssertIdentical(backoffEL, el2)
387389
guard let (failIndex, _) = connections.failConnection(startingID) else {
388390
return XCTFail("Expected that the connection is remembered")
389391
}

Tests/AsyncHTTPClientTests/HTTPConnectionPool+HTTP2ConnectionsTest.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ class HTTPConnectionPool_HTTP2ConnectionsTests: XCTestCase {
331331
XCTAssertEqual(connections.closeConnection(at: releaseIndex), leasedConn)
332332
XCTAssertFalse(connections.isEmpty)
333333

334+
let backoffEL = connections.backoffNextConnectionAttempt(startingID)
335+
XCTAssertIdentical(el6, backoffEL)
334336
guard let (failIndex, _) = connections.failConnection(startingID) else {
335337
return XCTFail("Expected that the connection is remembered")
336338
}

0 commit comments

Comments
 (0)