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

test: override connect_timeout and read_timeout in clients #2333

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions aws/sdk/integration-tests/dynamodb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ bytes = "1.0.0"
criterion = { version = "0.4.0" }
futures-util = "0.3.16"
http = "0.2.0"
hyper-rustls = { version = "0.23.2", features = ["webpki-tokio"] }
serde_json = "1.0.0"
tokio = { version = "1.8.4", features = ["full", "test-util"] }
tracing-subscriber = { version = "0.3.15", features = ["env-filter"] }
Expand Down
64 changes: 63 additions & 1 deletion aws/sdk/integration-tests/dynamodb/tests/timeouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ use std::time::Duration;
use aws_credential_types::provider::SharedCredentialsProvider;
use aws_credential_types::Credentials;
use aws_sdk_dynamodb::types::SdkError;
use aws_smithy_async::rt::sleep::{AsyncSleep, Sleep};
use aws_smithy_async::rt::sleep::{default_async_sleep, AsyncSleep, Sleep};
use aws_smithy_client::hyper_ext;
use aws_smithy_client::never::NeverConnector;
use aws_smithy_types::error::display::DisplayErrorContext;
use aws_smithy_types::retry::RetryConfig;
use aws_smithy_types::timeout::TimeoutConfig;
use aws_types::region::Region;
Expand Down Expand Up @@ -57,6 +59,66 @@ async fn api_call_timeout_retries() {
);
}

#[tokio::test]
async fn building_client_from_sdk_config_allows_to_override_connect_timeout() {
let connect_timeout_value = 100;
let connector = hyper_rustls::HttpsConnectorBuilder::new()
.with_webpki_roots()
.https_or_http()
.enable_http1()
.build();
let conf = SdkConfig::builder()
.region(Some(Region::from_static("us-east-1")))
.endpoint_url(
// Emulate a connect timeout error by hitting an unroutable IP
"http://172.255.255.0:18104",
)
.http_connector(
hyper_ext::Adapter::builder()
// // feel free to uncomment this if you want to make sure that the test pass when timeout is correctly set
// .connector_settings(
// aws_smithy_client::http_connector::ConnectorSettings::builder()
// .connect_timeout(Duration::from_millis(connect_timeout_value))
// .build(),
// )
.build(connector),
)
.credentials_provider(SharedCredentialsProvider::new(Credentials::for_tests()))
.retry_config(RetryConfig::disabled())
.sleep_impl(default_async_sleep().unwrap())
.build();

// overwrite connect_timeout config with Client::from_conf
let client = aws_sdk_dynamodb::Client::from_conf(
aws_sdk_dynamodb::config::Builder::from(&conf)
.timeout_config(
TimeoutConfig::builder()
.connect_timeout(Duration::from_millis(connect_timeout_value))
.build(),
)
.build(),
);

if let Ok(result) =
tokio::time::timeout(Duration::from_millis(1000), client.list_tables().send()).await
{
match result {
Ok(_) => panic!("should not have succeeded"),
Err(err) => {
let message = format!("{}", DisplayErrorContext(&err));
let expected =
format!("timeout: error trying to connect: HTTP connect timeout occurred after {connect_timeout_value}ms");
assert!(
message.contains(&expected),
"expected '{message}' to contain '{expected}'"
);
}
}
} else {
panic!("the client didn't timeout");
}
}

#[tokio::test]
async fn no_retries_on_operation_timeout() {
let conn = NeverConnector::new();
Expand Down