Skip to content

Commit 1751208

Browse files
committed
format and linux XCTest
1 parent b7c5edd commit 1751208

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

Diff for: Sources/AsyncHTTPClient/ConnectionPool/State Machine/HTTPConnectionPool+HTTP2StateMachine.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,11 @@ extension HTTPConnectionPool {
378378
if self.http1Connections!.isEmpty {
379379
self.http1Connections = nil
380380
}
381-
switch state {
381+
switch self.state {
382382
case .running:
383383
return .none
384384
case .shuttingDown(let unclean):
385-
if self.http1Connections == nil && self.connections.isEmpty {
385+
if self.http1Connections == nil, self.connections.isEmpty {
386386
return .init(
387387
request: .none,
388388
connection: .cleanupConnections(.init(), isShutdown: .yes(unclean: unclean))
@@ -407,9 +407,9 @@ extension HTTPConnectionPool {
407407
}
408408
// if there are no more http1Connections, we can remove the struct.
409409
self.http1Connections = nil
410-
410+
411411
// we must also check, if we are shutting down. Was this maybe out last connection?
412-
switch state {
412+
switch self.state {
413413
case .running:
414414
return .init(request: .none, connection: .closeConnection(connection, isShutdown: .no))
415415
case .shuttingDown(let unclean):
@@ -440,7 +440,7 @@ extension HTTPConnectionPool {
440440
// If there aren't any more connections, everything is shutdown
441441
let isShutdown: StateMachine.ConnectionAction.IsShutdown
442442
let unclean = !(cleanupContext.cancel.isEmpty && waitingRequests.isEmpty && self.http1Connections == nil)
443-
if self.connections.isEmpty && self.http1Connections == nil {
443+
if self.connections.isEmpty, self.http1Connections == nil {
444444
isShutdown = .yes(unclean: unclean)
445445
self.state = .shutDown
446446
} else {

Diff for: Tests/AsyncHTTPClientTests/HTTPConnectionPool+HTTP2StateMachineTests+XCTest.swift

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extension HTTPConnectionPool_HTTP2StateMachineTests {
2929
("testConnectionFailureBackoff", testConnectionFailureBackoff),
3030
("testCancelRequestWorks", testCancelRequestWorks),
3131
("testExecuteOnShuttingDownPool", testExecuteOnShuttingDownPool),
32+
("testHTTP1ToHTTP2MigrationAndShutdownIfFirstConnectionIsHTTP1", testHTTP1ToHTTP2MigrationAndShutdownIfFirstConnectionIsHTTP1),
3233
]
3334
}
3435
}

Diff for: Tests/AsyncHTTPClientTests/HTTPConnectionPool+HTTP2StateMachineTests.swift

+10-12
Original file line numberDiff line numberDiff line change
@@ -261,19 +261,19 @@ class HTTPConnectionPool_HTTP2StateMachineTests: XCTestCase {
261261
XCTAssertEqual(closeAction.connection, .cleanupConnections(.init(), isShutdown: .yes(unclean: true)))
262262
XCTAssertEqual(closeAction.request, .none)
263263
}
264-
264+
265265
func testHTTP1ToHTTP2MigrationAndShutdownIfFirstConnectionIsHTTP1() {
266266
let elg = EmbeddedEventLoopGroup(loops: 4)
267267
let el1 = elg.next()
268-
268+
269269
let idGenerator = HTTPConnectionPool.Connection.ID.Generator()
270270
var http1State = HTTPConnectionPool.HTTP1StateMachine(idGenerator: idGenerator, maximumConcurrentConnections: 8)
271-
271+
272272
let mockRequest1 = MockHTTPRequest(eventLoop: el1)
273273
let request1 = HTTPConnectionPool.Request(mockRequest1)
274274
let mockRequest2 = MockHTTPRequest(eventLoop: el1)
275275
let request2 = HTTPConnectionPool.Request(mockRequest2)
276-
276+
277277
let executeAction1 = http1State.executeRequest(request1)
278278
XCTAssertEqual(executeAction1.request, .scheduleRequestTimeout(for: request1, on: el1))
279279
guard case .createConnection(let conn1ID, _) = executeAction1.connection else {
@@ -284,44 +284,42 @@ class HTTPConnectionPool_HTTP2StateMachineTests: XCTestCase {
284284
guard case .createConnection(let conn2ID, _) = executeAction2.connection else {
285285
return XCTFail("unexpected connection action \(executeAction2.connection)")
286286
}
287-
287+
288288
// first connection is a HTTP1 connection
289289
let conn1: HTTPConnectionPool.Connection = .__testOnly_connection(id: conn1ID, eventLoop: el1)
290290
let conn1Action = http1State.newHTTP1ConnectionEstablished(conn1)
291291
XCTAssertEqual(conn1Action.connection, .none)
292292
XCTAssertEqual(conn1Action.request, .executeRequest(request1, conn1, cancelTimeout: true))
293293

294-
295294
// second connection is a HTTP2 connection and we need to migrate
296295
let conn2: HTTPConnectionPool.Connection = .__testOnly_connection(id: conn2ID, eventLoop: el1)
297296
var http2State = HTTPConnectionPool.HTTP2StateMachine(idGenerator: idGenerator)
298-
297+
299298
let migrationAction = http2State.migrateConnectionsFromHTTP1(
300299
connections: http1State.connections,
301300
requests: http1State.requests
302301
)
303302
XCTAssertEqual(migrationAction, .none)
304-
303+
305304
let http2ConnectAction = http2State.newHTTP2ConnectionEstablished(conn2, maxConcurrentStreams: 100)
306305
XCTAssertEqual(http2ConnectAction.connection, .none)
307306
guard case .executeRequestsAndCancelTimeouts([request2], conn2) = http2ConnectAction.request else {
308307
return XCTFail("Unexpected request action \(http2ConnectAction.request)")
309308
}
310-
309+
311310
// second request is done first
312311
let closeAction = http2State.http2ConnectionStreamClosed(conn2ID)
313312
XCTAssertEqual(closeAction.request, .none)
314313
XCTAssertEqual(closeAction.connection, .scheduleTimeoutTimer(conn2ID, on: el1))
315-
316-
314+
317315
let shutdownAction = http2State.shutdown()
318316
XCTAssertEqual(shutdownAction.request, .none)
319317
XCTAssertEqual(shutdownAction.connection, .cleanupConnections(.init(
320318
close: [conn2],
321319
cancel: [],
322320
connectBackoff: []
323321
), isShutdown: .no))
324-
322+
325323
let releaseAction = http2State.http1ConnectionReleased(conn1ID)
326324
XCTAssertEqual(releaseAction.request, .none)
327325
XCTAssertEqual(releaseAction.connection, .closeConnection(conn1, isShutdown: .yes(unclean: true)))

0 commit comments

Comments
 (0)