Unverified Commit cf8df40f authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

Merge `sra-test` into the SDK integration tests and fix its tests (#2883)

This PR merges the benchmark and integration tests from `aws/sra-test`
into the SDK integration tests, and updates the tests so that they
compile and pass.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent 55a1536e
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@
 */

use crate::service_clock_skew::ServiceClockSkew;
use aws_smithy_async::time::TimeSource;
use aws_smithy_runtime_api::box_error::BoxError;
use aws_smithy_runtime_api::client::interceptors::context::BeforeTransmitInterceptorContextMut;
use aws_smithy_runtime_api::client::interceptors::Interceptor;
@@ -16,7 +17,7 @@ use aws_smithy_types::timeout::TimeoutConfig;
use aws_smithy_types::DateTime;
use http::{HeaderName, HeaderValue};
use std::borrow::Cow;
use std::time::{Duration, SystemTime};
use std::time::Duration;

#[allow(clippy::declare_interior_mutable_const)] // we will never mutate this
const AMZ_SDK_REQUEST: HeaderName = HeaderName::from_static("amz-sdk-request");
@@ -63,11 +64,15 @@ impl RequestInfoInterceptor {
        }
    }

    fn build_ttl_pair(&self, cfg: &ConfigBag) -> Option<(Cow<'static, str>, Cow<'static, str>)> {
    fn build_ttl_pair(
        &self,
        cfg: &ConfigBag,
        timesource: impl TimeSource,
    ) -> Option<(Cow<'static, str>, Cow<'static, str>)> {
        let timeout_config = cfg.load::<TimeoutConfig>()?;
        let socket_read = timeout_config.read_timeout()?;
        let estimated_skew: Duration = cfg.load::<ServiceClockSkew>().cloned()?.into();
        let current_time = SystemTime::now();
        let current_time = timesource.now();
        let ttl = current_time.checked_add(socket_read + estimated_skew)?;
        let mut timestamp = DateTime::from(ttl);
        // Set subsec_nanos to 0 so that the formatted `DateTime` won't have fractional seconds.
@@ -94,11 +99,16 @@ impl Interceptor for RequestInfoInterceptor {
    fn modify_before_transmit(
        &self,
        context: &mut BeforeTransmitInterceptorContextMut<'_>,
        _runtime_components: &RuntimeComponents,
        runtime_components: &RuntimeComponents,
        cfg: &mut ConfigBag,
    ) -> Result<(), BoxError> {
        let mut pairs = RequestPairs::new();
        if let Some(pair) = self.build_ttl_pair(cfg) {
        if let Some(pair) = self.build_ttl_pair(
            cfg,
            runtime_components
                .time_source()
                .ok_or("A timesource must be provided")?,
        ) {
            pairs = pairs.with_pair(pair);
        }
        if let Some(pair) = self.build_attempts_pair(cfg) {
+2 −7
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.writable
import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization
import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection
import software.amazon.smithy.rust.codegen.core.testutil.testDependenciesOnly
import software.amazon.smithy.rustsdk.AwsCargoDependency.awsRuntime
import java.nio.file.Files
import java.nio.file.Paths
import kotlin.io.path.absolute
@@ -99,6 +100,7 @@ class IntegrationTestDependencies(
                if (codegenContext.smithyRuntimeMode.generateOrchestrator) {
                    addDependency(smithyRuntime(runtimeConfig).copy(features = setOf("test-util"), scope = DependencyScope.Dev))
                    addDependency(smithyRuntimeApi(runtimeConfig).copy(features = setOf("test-util"), scope = DependencyScope.Dev))
                    addDependency(awsRuntime(runtimeConfig).toDevDependency().withFeature("test-util"))
                }
            }
            if (hasBenches) {
@@ -148,12 +150,5 @@ class S3TestDependencies(private val codegenContext: ClientCodegenContext) : Lib
            addDependency(TempFile)
            addDependency(TracingAppender)
            addDependency(TracingTest)

            // TODO(enableNewSmithyRuntimeCleanup): These additional dependencies may not be needed anymore when removing this flag
            // depending on if the sra-test is kept around or not.
            if (codegenContext.smithyRuntimeMode.generateOrchestrator) {
                addDependency(smithyRuntime(codegenContext.runtimeConfig).toDevDependency())
                addDependency(smithyRuntimeApi(codegenContext.runtimeConfig).toDevDependency())
            }
        }
}
+2451 −0

File added.

Preview size limit exceeded, changes collapsed.

+24 −0
Original line number Diff line number Diff line
[package]
name = "orchestrator-vs-middleware"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aws-config = { path = "../../build/aws-sdk/sdk/aws-config" }
aws-credential-types = { path = "../../build/aws-sdk/sdk/aws-credential-types", features = ["test-util"] }
aws-sdk-s3 = { path = "../../build/aws-sdk/sdk/s3" }
aws-smithy-client = { path = "../../build/aws-sdk/sdk/aws-smithy-client", features = ["test-util", "wiremock"] }
criterion = { version = "0.4", features = ["async_tokio"] }
http = "0.2.3"
middleware-s3 = { version = "0.28", package = "aws-sdk-s3", features = ["test-util"] }
middleware-smithy-client = { version = "0.55.3", package = "aws-smithy-client", features = ["test-util", "rustls"] }
tokio = { version = "1.23.1", features = ["macros", "test-util", "rt-multi-thread"] }

[profile.release]
debug = 1

[[bench]]
name = "middleware_vs_orchestrator"
harness = false
+6 −0
Original line number Diff line number Diff line
@@ -2,5 +2,5 @@

To run the benchmark:
```bash
./gradlew :aws:sra-test:assemble && (cd aws/sra-test/integration-tests/aws-sdk-s3 && cargo bench)
./gradlew :aws:sdk:assemble && (cd aws/sdk/integration-tests/s3 && cargo bench)
```
Loading