Skip to content

Commit e27aef4

Browse files
andreasleyLukasa
andauthored
Make ConnectionPool's retryConnectionEstablishment public (#744)
* Make ConnectionPool's `retryConnectionEstablishment` public * Unified tests to consistently use `enableFastFailureModeForTesting()` * Add `retryConnectionEstablishment` as optional parameter to the initializer of `HTTPClient.Configuration.ConnectionPool` * Reverted change to initializer to prevent API stability breakage * Add parameterless initializer for `HTTPClient.Configuration.ConnectionPool` * Moved default values for `HTTPClient.Configuration.ConnectionPool` to the property declarations, so they only have to be specified at one point * Removed superfluous spaces Co-authored-by: Cory Benfield <[email protected]> * Re-added missing line break --------- Co-authored-by: Cory Benfield <[email protected]>
1 parent 0ae99db commit e27aef4

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

Sources/AsyncHTTPClient/HTTPClient.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,11 +1012,11 @@ extension HTTPClient.Configuration {
10121012
public struct ConnectionPool: Hashable, Sendable {
10131013
/// Specifies amount of time connections are kept idle in the pool. After this time has passed without a new
10141014
/// request the connections are closed.
1015-
public var idleTimeout: TimeAmount
1015+
public var idleTimeout: TimeAmount = .seconds(60)
10161016

10171017
/// The maximum number of connections that are kept alive in the connection pool per host. If requests with
10181018
/// an explicit eventLoopRequirement are sent, this number might be exceeded due to overflow connections.
1019-
public var concurrentHTTP1ConnectionsPerHostSoftLimit: Int
1019+
public var concurrentHTTP1ConnectionsPerHostSoftLimit: Int = 8
10201020

10211021
/// If true, ``HTTPClient`` will try to create new connections on connection failure with an exponential backoff.
10221022
/// Requests will only fail after the ``HTTPClient/Configuration/Timeout-swift.struct/connect`` timeout exceeded.
@@ -1025,16 +1025,17 @@ extension HTTPClient.Configuration {
10251025
/// - warning: We highly recommend leaving this on.
10261026
/// It is very common that connections establishment is flaky at scale.
10271027
/// ``HTTPClient`` will automatically mitigate these kind of issues if this flag is turned on.
1028-
var retryConnectionEstablishment: Bool
1028+
public var retryConnectionEstablishment: Bool = true
10291029

1030-
public init(idleTimeout: TimeAmount = .seconds(60)) {
1031-
self.init(idleTimeout: idleTimeout, concurrentHTTP1ConnectionsPerHostSoftLimit: 8)
1030+
public init() {}
1031+
1032+
public init(idleTimeout: TimeAmount) {
1033+
self.idleTimeout = idleTimeout
10321034
}
10331035

10341036
public init(idleTimeout: TimeAmount, concurrentHTTP1ConnectionsPerHostSoftLimit: Int) {
10351037
self.idleTimeout = idleTimeout
10361038
self.concurrentHTTP1ConnectionsPerHostSoftLimit = concurrentHTTP1ConnectionsPerHostSoftLimit
1037-
self.retryConnectionEstablishment = true
10381039
}
10391040
}
10401041

Tests/AsyncHTTPClientTests/HTTPClientNIOTSTests.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ class HTTPClientNIOTSTests: XCTestCase {
5555
guard isTestingNIOTS() else { return }
5656

5757
let httpBin = HTTPBin(.http1_1(ssl: true))
58-
var config = HTTPClient.Configuration()
59-
config.networkFrameworkWaitForConnectivity = false
60-
config.connectionPool.retryConnectionEstablishment = false
58+
let config = HTTPClient.Configuration()
59+
.enableFastFailureModeForTesting()
6160
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
6261
configuration: config)
6362
defer {
@@ -84,9 +83,8 @@ class HTTPClientNIOTSTests: XCTestCase {
8483
guard isTestingNIOTS() else { return }
8584
#if canImport(Network)
8685
let httpBin = HTTPBin(.http1_1(ssl: false))
87-
var config = HTTPClient.Configuration()
88-
config.networkFrameworkWaitForConnectivity = false
89-
config.connectionPool.retryConnectionEstablishment = false
86+
let config = HTTPClient.Configuration()
87+
.enableFastFailureModeForTesting()
9088

9189
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
9290
configuration: config)
@@ -140,9 +138,8 @@ class HTTPClientNIOTSTests: XCTestCase {
140138
tlsConfig.minimumTLSVersion = .tlsv11
141139
tlsConfig.maximumTLSVersion = .tlsv1
142140

143-
var clientConfig = HTTPClient.Configuration(tlsConfiguration: tlsConfig)
144-
clientConfig.networkFrameworkWaitForConnectivity = false
145-
clientConfig.connectionPool.retryConnectionEstablishment = false
141+
let clientConfig = HTTPClient.Configuration(tlsConfiguration: tlsConfig)
142+
.enableFastFailureModeForTesting()
146143
let httpClient = HTTPClient(
147144
eventLoopGroupProvider: .shared(self.clientGroup),
148145
configuration: clientConfig

0 commit comments

Comments
 (0)