From b8ba886a346828c892f7d5a535d6e4e09b4e8f21 Mon Sep 17 00:00:00 2001 From: Gus Cairo Date: Wed, 20 Dec 2023 18:30:07 -0300 Subject: [PATCH 1/2] Use the given connection pool idle timeout in the HTTPClient.Configuration inits --- Sources/AsyncHTTPClient/HTTPClient.swift | 4 ++-- .../HTTPClientTests.swift | 20 ++++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Sources/AsyncHTTPClient/HTTPClient.swift b/Sources/AsyncHTTPClient/HTTPClient.swift index 6fc94de5c..d6d02c94f 100644 --- a/Sources/AsyncHTTPClient/HTTPClient.swift +++ b/Sources/AsyncHTTPClient/HTTPClient.swift @@ -775,7 +775,7 @@ public class HTTPClient { self.init(tlsConfiguration: tlsConfig, redirectConfiguration: redirectConfiguration, timeout: timeout, - connectionPool: ConnectionPool(), + connectionPool: ConnectionPool(idleTimeout: maximumAllowedIdleTimeInConnectionPool), proxy: proxy, ignoreUncleanSSLShutdown: ignoreUncleanSSLShutdown, decompression: decompression) @@ -794,7 +794,7 @@ public class HTTPClient { self.init(tlsConfiguration: tlsConfig, redirectConfiguration: redirectConfiguration, timeout: timeout, - connectionPool: ConnectionPool(), + connectionPool: ConnectionPool(idleTimeout: connectionPool), proxy: proxy, ignoreUncleanSSLShutdown: ignoreUncleanSSLShutdown, decompression: decompression) diff --git a/Tests/AsyncHTTPClientTests/HTTPClientTests.swift b/Tests/AsyncHTTPClientTests/HTTPClientTests.swift index 291d522fb..4ec762101 100644 --- a/Tests/AsyncHTTPClientTests/HTTPClientTests.swift +++ b/Tests/AsyncHTTPClientTests/HTTPClientTests.swift @@ -1847,11 +1847,29 @@ final class HTTPClientTests: XCTestCaseHTTPClientTestsBaseClass { } func testPoolClosesIdleConnections() { + let configuration = HTTPClient.Configuration( + certificateVerification: .none, + maximumAllowedIdleTimeInConnectionPool: .milliseconds(100) + ) + let localClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup), - configuration: .init(connectionPool: .init(idleTimeout: .milliseconds(100)))) + configuration: configuration) defer { XCTAssertNoThrow(try localClient.syncShutdown()) } + + // Make sure that the idle timeout of the connection pool is properly propagated + // to the connection pool itself, when using both inits. + XCTAssertEqual(configuration.connectionPool.idleTimeout, .milliseconds(100)) + XCTAssertEqual( + configuration.connectionPool.idleTimeout, + HTTPClient.Configuration( + certificateVerification: .none, + connectionPool: .milliseconds(100), + backgroundActivityLogger: nil + ).connectionPool.idleTimeout + ) + XCTAssertNoThrow(try localClient.get(url: self.defaultHTTPBinURLPrefix + "get").wait()) Thread.sleep(forTimeInterval: 0.2) XCTAssertEqual(self.defaultHTTPBin.activeConnections, 0) From e5f06e3eeb39e1f5ea7487e2f77987383a395a6a Mon Sep 17 00:00:00 2001 From: Gus Cairo Date: Thu, 21 Dec 2023 09:13:22 -0300 Subject: [PATCH 2/2] Formatting --- Tests/AsyncHTTPClientTests/HTTPClientTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/AsyncHTTPClientTests/HTTPClientTests.swift b/Tests/AsyncHTTPClientTests/HTTPClientTests.swift index 4ec762101..075530f4e 100644 --- a/Tests/AsyncHTTPClientTests/HTTPClientTests.swift +++ b/Tests/AsyncHTTPClientTests/HTTPClientTests.swift @@ -1851,13 +1851,13 @@ final class HTTPClientTests: XCTestCaseHTTPClientTestsBaseClass { certificateVerification: .none, maximumAllowedIdleTimeInConnectionPool: .milliseconds(100) ) - + let localClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup), configuration: configuration) defer { XCTAssertNoThrow(try localClient.syncShutdown()) } - + // Make sure that the idle timeout of the connection pool is properly propagated // to the connection pool itself, when using both inits. XCTAssertEqual(configuration.connectionPool.idleTimeout, .milliseconds(100))