From 78d9e6fec8085b4bd84a58d03c58fbdf53e3d858 Mon Sep 17 00:00:00 2001 From: Oliver THEBAULT Date: Wed, 8 Feb 2023 20:47:39 +0100 Subject: [PATCH 1/2] test: connect_timeout and read_timeout bug --- aws/sdk/integration-tests/dynamodb/Cargo.toml | 1 + .../dynamodb/tests/timeouts.rs | 65 ++++++++++++++++++- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/aws/sdk/integration-tests/dynamodb/Cargo.toml b/aws/sdk/integration-tests/dynamodb/Cargo.toml index bf47eddcca..35f47db332 100644 --- a/aws/sdk/integration-tests/dynamodb/Cargo.toml +++ b/aws/sdk/integration-tests/dynamodb/Cargo.toml @@ -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"] } diff --git a/aws/sdk/integration-tests/dynamodb/tests/timeouts.rs b/aws/sdk/integration-tests/dynamodb/tests/timeouts.rs index 5695b403d8..06ccab2d36 100644 --- a/aws/sdk/integration-tests/dynamodb/tests/timeouts.rs +++ b/aws/sdk/integration-tests/dynamodb/tests/timeouts.rs @@ -9,8 +9,11 @@ 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::http_connector::ConnectorSettings; +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; @@ -57,6 +60,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( + // 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(); From ec796284cba1a9cd274b07f01480f4742cb17cb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Th=C3=A9bault?= Date: Mon, 13 Feb 2023 18:09:46 +0100 Subject: [PATCH 2/2] fix: ci --- aws/sdk/integration-tests/dynamodb/tests/timeouts.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/aws/sdk/integration-tests/dynamodb/tests/timeouts.rs b/aws/sdk/integration-tests/dynamodb/tests/timeouts.rs index 06ccab2d36..c7e04ee521 100644 --- a/aws/sdk/integration-tests/dynamodb/tests/timeouts.rs +++ b/aws/sdk/integration-tests/dynamodb/tests/timeouts.rs @@ -10,7 +10,6 @@ use aws_credential_types::provider::SharedCredentialsProvider; use aws_credential_types::Credentials; use aws_sdk_dynamodb::types::SdkError; use aws_smithy_async::rt::sleep::{default_async_sleep, AsyncSleep, Sleep}; -use aws_smithy_client::http_connector::ConnectorSettings; use aws_smithy_client::hyper_ext; use aws_smithy_client::never::NeverConnector; use aws_smithy_types::error::display::DisplayErrorContext; @@ -78,7 +77,7 @@ async fn building_client_from_sdk_config_allows_to_override_connect_timeout() { 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( - // ConnectorSettings::builder() + // aws_smithy_client::http_connector::ConnectorSettings::builder() // .connect_timeout(Duration::from_millis(connect_timeout_value)) // .build(), // )