Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ability to configure timeout in AWSClientConfiguration #1151

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func addClientRuntimeDependency(_ version: Version) {
]
case (false, true):
package.dependencies += [
.package(url: smithySwiftURL, .branch("main"))
.package(url: smithySwiftURL, .branch("day/expose-timeout"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be reverted back to main, this is only for CI

]
case (false, false):
package.dependencies += [
Expand Down
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 with use default values based on the operation system.
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_async_configureTimeoutOptionsFromParams() throws {
let customTimeout = 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 }
}
Loading