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

Split test-util feature to allow test-util to be utilized in WASM #2873

Merged
merged 2 commits into from
Jul 27, 2023
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion aws/rust-runtime/aws-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion aws/sdk/integration-tests/s3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
3 changes: 3 additions & 0 deletions rust-runtime/aws-smithy-async/additional-ci
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions rust-runtime/aws-smithy-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions rust-runtime/aws-smithy-client/additional-ci
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 13 additions & 6 deletions rust-runtime/aws-smithy-client/src/conns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
6 changes: 2 additions & 4 deletions rust-runtime/aws-smithy-client/src/dvr/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,9 +32,9 @@ pub struct RecordingConnection<S> {
pub(crate) inner: S,
}

impl RecordingConnection<Adapter<Https>> {
#[cfg(all(feature = "rustls", feature = "client-hyper"))]
impl RecordingConnection<crate::hyper_ext::Adapter<crate::conns::Https>> {
/// Construct a recording connection wrapping a default HTTPS implementation
#[cfg(feature = "rustls")]
pub fn https() -> Self {
Self {
data: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion rust-runtime/aws-smithy-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion rust-runtime/aws-smithy-client/src/test_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ impl tower::Service<http::Request<SdkBody>> 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};
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#![cfg(feature = "test-util")]
#![cfg(feature = "wiremock")]

mod test_operation;

Expand Down
Loading