Unverified Commit 8136ba4a authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Use provided sleep_impl in aws-smithy-client::retry (#923)

* Use provided sleep_impl in aws-smithy-client::retry

Previously, aws_smithy_client was hard coded to use tokio::sleep. This change:
- threads the sleep implementation into the retry controller
- moves the integration test out of aws-hyper and into aws-smithy-client
- takes a first pass at fixing the cargo featres (cargo hack --feature-powerset passes now)

* cleanups

* several test fixups

* Use tristate to conditionally log

* Update changelog
parent 80385399
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -10,6 +10,17 @@
# references = ["smithy-rs#920"]
# meta = { "breaking" = false, "tada" = false, "bug" = false }
# author = "rcoh"
[[aws-sdk-rust]]
message = "Use provided `sleep_impl` for retries instead of using Tokio directly."
references = ["smithy-rs#923"]
meta = { "breaking" = false, "tada" = false, "bug" = false }
author = "rcoh"

[[smithy-rs]]
message = "Use provided `sleep_impl` for retries instead of using Tokio directly."
references = ["smithy-rs#923"]
meta = { "breaking" = false, "tada" = false, "bug" = false }
author = "rcoh"

[[aws-sdk-rust]]
message = "Fix typos in module documentation for generated crates"
+1 −1
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ tower = { version = "0.4.8", optional = true }
futures-util = "0.3.16"
tracing-test = "0.1.0"

tokio = { version = "1", features = ["full"] }
tokio = { version = "1", features = ["full", "test-util"] }
# used to test compatibility
async-trait = "0.1.51"
env_logger = "0.9.0"
+7 −6
Original line number Diff line number Diff line
@@ -452,7 +452,7 @@ pub mod credentials {
    ///
    /// # Examples
    /// Create a default chain with a custom region:
    /// ```rust
    /// ```no_run
    /// use aws_types::region::Region;
    /// use aws_config::default_provider::credentials::DefaultCredentialsChain;
    /// let credentials_provider = DefaultCredentialsChain::builder()
@@ -461,13 +461,13 @@ pub mod credentials {
    /// ```
    ///
    /// Create a default chain with no overrides:
    /// ```rust
    /// ```no_run
    /// use aws_config::default_provider::credentials::DefaultCredentialsChain;
    /// let credentials_provider = DefaultCredentialsChain::builder().build();
    /// ```
    ///
    /// Create a default chain that uses a different profile:
    /// ```rust
    /// ```no_run
    /// use aws_config::default_provider::credentials::DefaultCredentialsChain;
    /// let credentials_provider = DefaultCredentialsChain::builder()
    ///     .profile_name("otherprofile")
@@ -613,19 +613,19 @@ pub mod credentials {
        ///
        /// # Examples
        /// **Run the test case in `test-data/default-provider-chain/test_name`
        /// ```rust
        /// ```no_run
        /// make_test!(test_name);
        /// ```
        ///
        /// **Update (responses are replayed but new requests are recorded) the test case**:
        /// ```rust
        /// ```no_run
        /// make_test!(update: test_name)
        /// ```
        ///
        /// **Run the test case against a real HTTPS connection:**
        /// > Note: Be careful to remove sensitive information before committing. Always use a temporary
        /// > AWS account when recording live traffic.
        /// ```rust
        /// ```no_run
        /// make_test!(live: test_name)
        /// ```
        macro_rules! make_test {
@@ -702,6 +702,7 @@ pub mod credentials {
        #[tokio::test]
        #[traced_test]
        async fn no_providers_configured_err() {
            tokio::time::pause();
            let conf = ProviderConfig::no_configuration()
                .with_tcp_connector(BoxCloneService::new(NeverConnected::new()))
                .with_time_source(TimeSource::real())
+16 −6
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ fn user_agent() -> AwsUserAgent {
///
/// ## Endpoint configuration list
/// 1. Explicit configuration of `Endpoint` via the [builder](Builder):
/// ```rust
/// ```no_run
/// use aws_config::imds::client::Client;
/// use http::Uri;
/// # async fn docs() {
@@ -92,7 +92,7 @@ fn user_agent() -> AwsUserAgent {
/// ```
///
/// 4. An explicitly set endpoint mode:
/// ```rust
/// ```no_run
/// use aws_config::imds::client::{Client, EndpointMode};
/// # async fn docs() {
/// let client = Client::builder().endpoint_mode(EndpointMode::IpV6).build().await;
@@ -170,7 +170,7 @@ impl Client {
    ///
    /// # Examples
    ///
    /// ```rust
    /// ```no_run
    /// use aws_config::imds::client::Client;
    /// # async fn docs() {
    /// let client = Client::builder().build().await.expect("valid client");
@@ -456,7 +456,7 @@ impl Builder {
    /// Configure generic options of the [`Client`]
    ///
    /// # Examples
    /// ```rust
    /// ```no_run
    /// use aws_config::imds::Client;
    /// # async fn test() {
    /// use aws_config::provider_config::ProviderConfig;
@@ -555,12 +555,16 @@ impl Builder {
            timeout_config.clone(),
        );
        let middleware = ImdsMiddleware { token_loader };
        let inner_client = aws_smithy_client::Builder::new()
        let mut inner_client = aws_smithy_client::Builder::new()
            .connector(connector.clone())
            .middleware(middleware)
            .build()
            .with_retry_config(retry_config)
            .with_timeout_config(timeout_config);
        if let Some(sleep) = config.sleep() {
            inner_client = inner_client.with_sleep_impl(sleep);
        }

        let client = Client {
            endpoint,
            inner: inner_client,
@@ -721,6 +725,7 @@ pub(crate) mod test {
    use std::time::{Duration, SystemTime, UNIX_EPOCH};

    use aws_hyper::DynConnector;
    use aws_smithy_async::rt::sleep::TokioSleep;
    use aws_smithy_client::test_connection::{capture_request, TestConnection};
    use aws_smithy_http::body::SdkBody;
    use aws_types::os_shim_internal::{Env, Fs, ManualTimeSource, TimeSource};
@@ -770,9 +775,11 @@ pub(crate) mod test {
        SdkBody: From<T>,
        T: Send + 'static,
    {
        tokio::time::pause();
        super::Client::builder()
            .configure(
                &ProviderConfig::no_configuration()
                    .with_sleep(TokioSleep::new())
                    .with_http_connector(DynConnector::new(conn.clone())),
            )
            .build()
@@ -827,11 +834,13 @@ pub(crate) mod test {
            ),
        ]);
        let mut time_source = ManualTimeSource::new(UNIX_EPOCH);
        tokio::time::pause();
        let client = super::Client::builder()
            .configure(
                &ProviderConfig::no_configuration()
                    .with_http_connector(DynConnector::new(connection.clone()))
                    .with_time_source(TimeSource::manual(&time_source)),
                    .with_time_source(TimeSource::manual(&time_source))
                    .with_sleep(TokioSleep::new()),
            )
            .endpoint_mode(EndpointMode::IpV6)
            .token_ttl(Duration::from_secs(600))
@@ -876,6 +885,7 @@ pub(crate) mod test {
                imds_response(r#"test-imds-output3"#),
            ),
        ]);
        tokio::time::pause();
        let mut time_source = ManualTimeSource::new(UNIX_EPOCH);
        let client = super::Client::builder()
            .configure(
+2 −6
Original line number Diff line number Diff line
@@ -12,10 +12,10 @@ use crate::imds;
use crate::imds::client::LazyClient;
use crate::meta::region::{future, ProvideRegion};
use crate::provider_config::ProviderConfig;
use aws_smithy_async::rt::sleep::AsyncSleep;

use aws_types::os_shim_internal::Env;
use aws_types::region::Region;
use std::sync::Arc;

use tracing::Instrument;

/// IMDSv2 Region Provider
@@ -24,7 +24,6 @@ use tracing::Instrument;
#[derive(Debug)]
pub struct ImdsRegionProvider {
    client: LazyClient,
    sleep: Arc<dyn AsyncSleep>,
    env: Env,
}

@@ -110,9 +109,6 @@ impl Builder {
        ImdsRegionProvider {
            client,
            env: provider_config.env(),
            sleep: provider_config
                .sleep()
                .expect("no default sleep implementation provided"),
        }
    }
}
Loading