Unverified Commit 1297c8c7 authored by ysaito1001's avatar ysaito1001 Committed by GitHub
Browse files

Avoid a real connection in unit test (#3063)

## Motivation and Context
Fixes a flaky test that misbehaves as follows:
```
---- tests_1::test_specifying_credentials_provider_only_at_operation_level_should_work stdout ----
thread 'tests_1::test_specifying_credentials_provider_only_at_operation_level_should_work' panicked at 'success: DispatchFailure(DispatchFailure { source: ConnectorError { kind: Io, sour
ce: hyper::Error(Connect, ConnectError("tcp connect error", Os { code: 110, kind: TimedOut, message: "Connection timed out" })), connection: Unknown } })', smithy-test9200972819374912606/src
/lib.rs:105:14
```

## Description
Because the fix is meant for the release branch, it uses a
`TestConnection` rather than a `StaticReplayClient`, which is available
only in the `main` branch. Code needs to be upgraded when the PR is
back-ported to the `main` branch.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent af8474aa
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ package software.amazon.smithy.rustsdk

import org.junit.jupiter.api.Test
import software.amazon.smithy.rust.codegen.core.rustlang.Attribute
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel
@@ -61,8 +62,12 @@ internal class CredentialCacheConfigTest {
                "Region" to AwsRuntimeType.awsTypes(runtimeConfig).resolve("region::Region"),
                "RuntimePlugin" to RuntimeType.smithyRuntimeApi(runtimeConfig)
                    .resolve("client::runtime_plugin::RuntimePlugin"),
                "SdkBody" to RuntimeType.sdkBody(runtimeConfig),
                "SharedCredentialsCache" to AwsRuntimeType.awsCredentialTypes(runtimeConfig)
                    .resolve("cache::SharedCredentialsCache"),
                "TestConnection" to CargoDependency.smithyClient(runtimeConfig)
                    .toDevDependency().withFeature("test-util").toType()
                    .resolve("test_connection::TestConnection"),
            )
            rustCrate.testModule {
                unitTest(
@@ -138,7 +143,18 @@ internal class CredentialCacheConfigTest {
                    // per https://github.com/awslabs/aws-sdk-rust/issues/901
                    rustTemplate(
                        """
                        let client_config = crate::config::Config::builder().build();
                        let connector = #{TestConnection}::new(vec![(
                            http::Request::builder()
                                .body(#{SdkBody}::from("request body"))
                                .unwrap(),
                            http::Response::builder()
                                .status(200)
                                .body(#{SdkBody}::from("response"))
                                .unwrap(),
                        )]);
                        let client_config = crate::config::Config::builder()
                            .http_connector(connector.clone())
                            .build();
                        let client = crate::client::Client::from_conf(client_config);

                        let credentials = #{Credentials}::new(