From 1502555853151d363df7e455026518240444f785 Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Wed, 26 Jul 2023 10:14:39 -0400 Subject: [PATCH] Split test-util feature to allow test-util to be utilized in WASM contexts --- CHANGELOG.next.toml | 6 ++++++ aws/rust-runtime/aws-config/Cargo.toml | 2 +- .../rustsdk/IntegrationTestDependencies.kt | 2 +- aws/sdk/integration-tests/s3/Cargo.toml | 2 +- rust-runtime/aws-smithy-async/additional-ci | 3 +++ rust-runtime/aws-smithy-client/Cargo.toml | 7 ++++--- rust-runtime/aws-smithy-client/additional-ci | 4 ++++ rust-runtime/aws-smithy-client/src/conns.rs | 19 +++++++++++++------ .../aws-smithy-client/src/dvr/record.rs | 6 ++---- rust-runtime/aws-smithy-client/src/lib.rs | 2 +- .../aws-smithy-client/src/test_connection.rs | 3 ++- .../tests/reconnect_on_transient_error.rs | 2 +- 12 files changed, 39 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index 741a454094..0d7ba6dedb 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -686,3 +686,9 @@ x-amzn-errortype: InvalidRequestException references = ["smithy-rs#2866"] meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "server" } author = "david-perez" + +[[smithy-rs]] +message = "The `test-util` feature in aws-smithy-client has been split to include a separate `wiremock` feature. This allows test-util to be used without a Hyper server dependency making it usable in webassembly targets." +meta = { "breaking" = true, "tada" = false , "bug" = false, "target" = "client" } +author = "rcoh" +references = ["smithy-rs#2873"] diff --git a/aws/rust-runtime/aws-config/Cargo.toml b/aws/rust-runtime/aws-config/Cargo.toml index c19658d9c3..02853a8fe6 100644 --- a/aws/rust-runtime/aws-config/Cargo.toml +++ b/aws/rust-runtime/aws-config/Cargo.toml @@ -62,7 +62,7 @@ serde = { version = "1", features = ["derive"] } serde_json = "1" aws-credential-types = { path = "../../sdk/build/aws-sdk/sdk/aws-credential-types", features = ["test-util"] } -aws-smithy-client = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-client", features = ["test-util"] } +aws-smithy-client = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-client", features = ["test-util", "rt-tokio", "client-hyper"] } # used for a usage example hyper-rustls = { version = "0.24", features = ["webpki-tokio", "http2", "http1"] } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/IntegrationTestDependencies.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/IntegrationTestDependencies.kt index 38c7d76a83..5a39041ef2 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/IntegrationTestDependencies.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/IntegrationTestDependencies.kt @@ -83,7 +83,7 @@ class IntegrationTestDependencies( val smithyAsync = CargoDependency.smithyAsync(codegenContext.runtimeConfig) .copy(features = setOf("test-util"), scope = DependencyScope.Dev) val smithyClient = CargoDependency.smithyClient(codegenContext.runtimeConfig) - .copy(features = setOf("test-util"), scope = DependencyScope.Dev) + .copy(features = setOf("test-util", "wiremock"), scope = DependencyScope.Dev) val smithyTypes = CargoDependency.smithyTypes(codegenContext.runtimeConfig) .copy(features = setOf("test-util"), scope = DependencyScope.Dev) addDependency(smithyAsync) diff --git a/aws/sdk/integration-tests/s3/Cargo.toml b/aws/sdk/integration-tests/s3/Cargo.toml index 010d73f659..650d1a5db0 100644 --- a/aws/sdk/integration-tests/s3/Cargo.toml +++ b/aws/sdk/integration-tests/s3/Cargo.toml @@ -18,7 +18,7 @@ aws-http = { path = "../../build/aws-sdk/sdk/aws-http" } aws-sdk-s3 = { path = "../../build/aws-sdk/sdk/s3" } aws-sdk-sts = { path = "../../build/aws-sdk/sdk/sts" } aws-smithy-async = { path = "../../build/aws-sdk/sdk/aws-smithy-async", features = ["test-util", "rt-tokio"] } -aws-smithy-client = { path = "../../build/aws-sdk/sdk/aws-smithy-client", features = ["test-util", "rustls"] } +aws-smithy-client = { path = "../../build/aws-sdk/sdk/aws-smithy-client", features = ["test-util", "wiremock"] } aws-smithy-http = { path = "../../build/aws-sdk/sdk/aws-smithy-http" } aws-smithy-protocol-test = { path = "../../build/aws-sdk/sdk/aws-smithy-protocol-test" } aws-smithy-runtime = { path = "../../build/aws-sdk/sdk/aws-smithy-runtime", features = ["test-util"] } diff --git a/rust-runtime/aws-smithy-async/additional-ci b/rust-runtime/aws-smithy-async/additional-ci index fde542e9fc..2e342db6fa 100755 --- a/rust-runtime/aws-smithy-async/additional-ci +++ b/rust-runtime/aws-smithy-async/additional-ci @@ -8,6 +8,9 @@ set -e +echo '### Checking compilation under WASM' +cargo check --target wasm32-unknown-unknown + echo "### Checking for duplicate dependency versions in the normal dependency graph with all features enabled" cargo tree -d --edges normal --all-features diff --git a/rust-runtime/aws-smithy-client/Cargo.toml b/rust-runtime/aws-smithy-client/Cargo.toml index 826ce5eb3d..5426587c9d 100644 --- a/rust-runtime/aws-smithy-client/Cargo.toml +++ b/rust-runtime/aws-smithy-client/Cargo.toml @@ -9,11 +9,12 @@ repository = "https://github.com/awslabs/smithy-rs" [features] rt-tokio = ["aws-smithy-async/rt-tokio"] -test-util = ["dep:aws-smithy-protocol-test", "dep:hyper", "hyper?/server", "hyper?/h2", "dep:serde", "dep:serde_json", "serde?/derive", "rustls", "tokio/full"] +test-util = ["dep:aws-smithy-protocol-test", "dep:serde", "dep:serde_json", "serde?/derive"] +wiremock = ["test-util", "dep:hyper", "hyper?/server", "hyper?/h2", "rustls", "tokio/full"] native-tls = [] allow-compilation = [] # our tests use `cargo test --all-features` and native-tls breaks CI rustls = ["dep:hyper-rustls", "dep:lazy_static", "dep:rustls", "client-hyper", "rt-tokio"] -client-hyper = ["dep:hyper"] +client-hyper = ["dep:hyper", "hyper?/client", "hyper?/http2", "hyper?/http1", "hyper?/tcp"] hyper-webpki-doctest-only = ["dep:hyper-rustls", "hyper-rustls?/webpki-roots"] [dependencies] @@ -26,7 +27,7 @@ bytes = "1" fastrand = "2.0.0" http = "0.2.3" http-body = "0.4.4" -hyper = { version = "0.14.26", features = ["client", "http2", "http1", "tcp"], optional = true } +hyper = { version = "0.14.26", default-features = false, optional = true } # cargo does not support optional test dependencies, so to completely disable rustls # we need to add the webpki-roots feature here. # https://github.com/rust-lang/cargo/issues/1596 diff --git a/rust-runtime/aws-smithy-client/additional-ci b/rust-runtime/aws-smithy-client/additional-ci index bb21b8b01f..e2ada6a73e 100755 --- a/rust-runtime/aws-smithy-client/additional-ci +++ b/rust-runtime/aws-smithy-client/additional-ci @@ -8,6 +8,10 @@ set -e +# TODO(msrvUpgrade): This can be enabled when upgrading to Rust 1.71 +# echo '### Checking compilation under WASM' +# cargo hack check --no-dev-deps --target wasm32-unknown-unknown + echo "### Checking for duplicate dependency versions in the normal dependency graph with all features enabled" cargo tree -d --edges normal --all-features diff --git a/rust-runtime/aws-smithy-client/src/conns.rs b/rust-runtime/aws-smithy-client/src/conns.rs index d4e25c45aa..8ee1d8a929 100644 --- a/rust-runtime/aws-smithy-client/src/conns.rs +++ b/rust-runtime/aws-smithy-client/src/conns.rs @@ -202,12 +202,19 @@ mod custom_tls_tests { async fn send_request_and_assert_success(conn: DynConnector, uri: &Uri) { let mut svc = ServiceBuilder::new().service(conn); - let req = Request::builder() - .uri(uri) - .method(Method::GET) - .body(SdkBody::empty()) - .unwrap(); - let res = svc.call(req).await.unwrap(); + let mut att = 0; + let res = loop { + let req = Request::builder() + .uri(uri) + .method(Method::GET) + .body(SdkBody::empty()) + .unwrap(); + if let Ok(res) = svc.call(req).await { + break res; + } + assert!(att < 5); + att += 1; + }; assert!(res.status().is_success()); } } diff --git a/rust-runtime/aws-smithy-client/src/dvr/record.rs b/rust-runtime/aws-smithy-client/src/dvr/record.rs index 234bc23d64..9415528f73 100644 --- a/rust-runtime/aws-smithy-client/src/dvr/record.rs +++ b/rust-runtime/aws-smithy-client/src/dvr/record.rs @@ -18,8 +18,6 @@ use aws_smithy_http::body::SdkBody; use crate::dvr::{self, Action, BodyData, ConnectionId, Direction, Error, NetworkTraffic, Version}; use super::Event; -use crate::conns::Https; -use crate::hyper_ext::Adapter; use std::fmt::Display; use std::io; use std::path::Path; @@ -34,9 +32,9 @@ pub struct RecordingConnection { pub(crate) inner: S, } -impl RecordingConnection> { +#[cfg(all(feature = "rustls", feature = "client-hyper"))] +impl RecordingConnection> { /// Construct a recording connection wrapping a default HTTPS implementation - #[cfg(feature = "rustls")] pub fn https() -> Self { Self { data: Default::default(), diff --git a/rust-runtime/aws-smithy-client/src/lib.rs b/rust-runtime/aws-smithy-client/src/lib.rs index 935dddd2f0..82ddc4cacb 100644 --- a/rust-runtime/aws-smithy-client/src/lib.rs +++ b/rust-runtime/aws-smithy-client/src/lib.rs @@ -34,7 +34,7 @@ pub mod timeout; mod builder; pub use builder::Builder; -#[cfg(feature = "test-util")] +#[cfg(all(feature = "test-util", feature = "client-hyper"))] pub mod dvr; #[cfg(feature = "test-util")] pub mod test_connection; diff --git a/rust-runtime/aws-smithy-client/src/test_connection.rs b/rust-runtime/aws-smithy-client/src/test_connection.rs index 86466944df..a339eac6bb 100644 --- a/rust-runtime/aws-smithy-client/src/test_connection.rs +++ b/rust-runtime/aws-smithy-client/src/test_connection.rs @@ -358,6 +358,7 @@ impl tower::Service> for ConnectionFn { /// match_events!(ev!(dns), ev!(connect), ev!(http(200)))(&mock.events()); /// # } /// ``` +#[cfg(feature = "wiremock")] pub mod wire_mock { use bytes::Bytes; use http::{Request, Response}; @@ -673,7 +674,7 @@ pub mod wire_mock { #[cfg(test)] mod tests { - use hyper::service::Service; + use tower::Service; use aws_smithy_http::body::SdkBody; use aws_smithy_http::result::ConnectorError; diff --git a/rust-runtime/aws-smithy-client/tests/reconnect_on_transient_error.rs b/rust-runtime/aws-smithy-client/tests/reconnect_on_transient_error.rs index 3fc0fe133a..695e069cf1 100644 --- a/rust-runtime/aws-smithy-client/tests/reconnect_on_transient_error.rs +++ b/rust-runtime/aws-smithy-client/tests/reconnect_on_transient_error.rs @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#![cfg(feature = "test-util")] +#![cfg(feature = "wiremock")] mod test_operation;