Skip to content

Commit

Permalink
Use the given connection pool idle timeout in the HTTPClient.Configur…
Browse files Browse the repository at this point in the history
…ation inits (#723)
  • Loading branch information
gjcairo authored Dec 21, 2023
1 parent 75fce63 commit 5ccda44
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Sources/AsyncHTTPClient/HTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
20 changes: 19 additions & 1 deletion Tests/AsyncHTTPClientTests/HTTPClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5ccda44

Please sign in to comment.