Skip to content

Commit

Permalink
feat: add ability to configure timeout in AWSClientConfiguration (#1152)
Browse files Browse the repository at this point in the history
  • Loading branch information
dayaffe authored Sep 26, 2023
1 parent fc076b7 commit 8c3e24f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
27 changes: 21 additions & 6 deletions Sources/Core/AWSClientRuntime/AWSClientConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public class AWSClientConfiguration<ServiceSpecificConfiguration: AWSServiceSpec
/// This structure is custom code-generated for each AWS service.
public var serviceSpecific: ServiceSpecificConfiguration

/// The timeout for a request in milliseconds
///
/// If none is provided the client will use default values based on the platform.
public var connectTimeoutMs: UInt32?

/// Internal designated init
/// All convenience inits should call this.
private init(
Expand All @@ -115,7 +120,8 @@ public class AWSClientConfiguration<ServiceSpecificConfiguration: AWSServiceSpec
_ useFIPS: Swift.Bool?,
_ retryStrategyOptions: RetryStrategyOptions?,
_ appID: String?,
_ awsRetryMode: AWSRetryMode
_ awsRetryMode: AWSRetryMode,
_ connectTimeoutMs: UInt32? = nil
) throws {
typealias RuntimeConfigType =
DefaultSDKRuntimeConfiguration<DefaultRetryStrategy, DefaultRetryErrorInfoProvider>
Expand All @@ -128,8 +134,13 @@ public class AWSClientConfiguration<ServiceSpecificConfiguration: AWSServiceSpec
self.useDualStack = useDualStack
self.useFIPS = useFIPS
self.clientLogMode = RuntimeConfigType.defaultClientLogMode
self.connectTimeoutMs = connectTimeoutMs
self.httpClientConfiguration = RuntimeConfigType.defaultHttpClientConfiguration
self.httpClientEngine = RuntimeConfigType.defaultHttpClientEngine
if let connectTimeoutMs = self.connectTimeoutMs {
self.httpClientEngine = RuntimeConfigType.httpClientEngineWithTimeout(timeoutMs: connectTimeoutMs)
} else {
self.httpClientEngine = RuntimeConfigType.defaultHttpClientEngine
}
self.idempotencyTokenGenerator = RuntimeConfigType.defaultIdempotencyTokenGenerator
self.logger = RuntimeConfigType.defaultLogger(clientName: self.serviceSpecific.clientName)
self.retryStrategyOptions = retryStrategyOptions ?? RuntimeConfigType.defaultRetryStrategyOptions
Expand Down Expand Up @@ -162,7 +173,8 @@ extension AWSClientConfiguration {
useFIPS: Swift.Bool? = nil,
retryMode: AWSRetryMode? = nil,
maxAttempts: Int? = nil,
appID: String? = nil
appID: String? = nil,
connectTimeoutMs: UInt32? = nil
) async throws {
let fileBasedConfig = try await CRTFileBasedConfiguration.makeAsync()
let resolvedRegionResolver = try regionResolver ?? DefaultRegionResolver { _, _ in fileBasedConfig }
Expand Down Expand Up @@ -200,7 +212,8 @@ extension AWSClientConfiguration {
useFIPS,
retryStrategyOptions,
resolvedAppID,
resolvedAWSRetryMode
resolvedAWSRetryMode,
connectTimeoutMs
)
}

Expand All @@ -214,7 +227,8 @@ extension AWSClientConfiguration {
useFIPS: Swift.Bool? = nil,
retryMode: AWSRetryMode? = nil,
maxAttempts: Int? = nil,
appID: String? = nil
appID: String? = nil,
connectTimeoutMs: UInt32? = nil
) throws {
let fileBasedConfig = try CRTFileBasedConfiguration.make()
let resolvedCredentialsProvider: CredentialsProviding
Expand Down Expand Up @@ -245,7 +259,8 @@ extension AWSClientConfiguration {
useFIPS,
retryStrategyOptions,
resolvedAppID,
resolvedAWSRetryMode
resolvedAWSRetryMode,
connectTimeoutMs
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ class AWSClientConfigurationTests: XCTestCase {
let subject = try await Subject(region: region, appID: appID)
XCTAssertEqual(subject.appID, appID)
}

// MARK: - Timeout

func test_sync_configureTimeoutOptionsFromParams() throws {
let customTimeout: UInt32 = 10_000
let subject = try Subject(region: region, connectTimeoutMs: customTimeout)
XCTAssertEqual(subject.connectTimeoutMs, customTimeout)
}
}

struct TestAWSServiceSpecificConfiguration: AWSServiceSpecificConfiguration {
Expand All @@ -78,4 +86,5 @@ struct TestAWSServiceSpecificConfiguration: AWSServiceSpecificConfiguration {

var serviceName: String { "TestAWSService" }
var clientName: String { "TestAWSServiceClient" }
var connectTimeoutMs: UInt32 { 10_000 }
}

0 comments on commit 8c3e24f

Please sign in to comment.