-
Notifications
You must be signed in to change notification settings - Fork 252
Expand file tree
/
Copy pathTimeoutConfigMergingTest.kt
More file actions
171 lines (162 loc) · 8.12 KB
/
TimeoutConfigMergingTest.kt
File metadata and controls
171 lines (162 loc) · 8.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package software.amazon.smithy.rustsdk
import SdkCodegenIntegrationTest
import org.junit.jupiter.api.Test
import software.amazon.smithy.rust.codegen.core.rustlang.Attribute
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.core.rustlang.writable
import software.amazon.smithy.rust.codegen.core.testutil.integrationTest
class TimeoutConfigMergingTest {
@Test
fun testTimeoutSettingsProperlyMerged() {
awsSdkIntegrationTest(SdkCodegenIntegrationTest.model) { ctx, crate ->
val name = ctx.moduleUseName()
crate.integrationTest("timeout_settings_properly_merged") {
rustTemplate(
"""
use $name::Client;
use aws_smithy_runtime::test_util::capture_test_logs::capture_test_logs;
use aws_smithy_runtime_api::box_error::BoxError;
use aws_smithy_runtime_api::client::interceptors::context::BeforeTransmitInterceptorContextRef;
use aws_smithy_runtime_api::client::interceptors::Intercept;
use aws_smithy_runtime_api::client::runtime_components::RuntimeComponents;
use aws_smithy_runtime::client::http::test_util::infallible_client_fn;
use aws_smithy_types::config_bag::ConfigBag;
use aws_smithy_types::timeout::TimeoutConfig;
use aws_smithy_types::body::SdkBody;
use aws_types::SdkConfig;
use std::sync::Arc;
use std::sync::Mutex;
use std::time::Duration;
##[derive(Debug, Clone)]
struct CaptureConfigInterceptor {
timeout_config: Arc<Mutex<Option<TimeoutConfig>>>,
}
impl Intercept for CaptureConfigInterceptor {
fn name(&self) -> &'static str {
"capture config interceptor"
}
fn read_before_attempt(
&self,
_context: &BeforeTransmitInterceptorContextRef<'_>,
_runtime_components: &RuntimeComponents,
cfg: &mut ConfigBag,
) -> Result<(), BoxError> {
*self.timeout_config.lock().unwrap() = cfg.load::<TimeoutConfig>().cloned();
Ok(())
}
}
#{tokio_test}
async fn test_all_timeouts() {
let (_logs, _guard) = capture_test_logs();
let connect_timeout = Duration::from_secs(1);
let read_timeout = Duration::from_secs(2);
let operation_attempt = Duration::from_secs(3);
let operation = Duration::from_secs(4);
let http_client = infallible_client_fn(|_req| http::Response::builder().body(SdkBody::empty()).unwrap());
let sdk_config = SdkConfig::builder()
.behavior_version(aws_smithy_runtime_api::client::behavior_version::BehaviorVersion::v2026_01_12())
.timeout_config(
TimeoutConfig::builder()
.connect_timeout(connect_timeout)
.build(),
)
.http_client(http_client)
.build();
let client_config = $name::config::Builder::from(&sdk_config)
.timeout_config(TimeoutConfig::builder().read_timeout(read_timeout).build())
.build();
let client = Client::from_conf(client_config);
let interceptor = CaptureConfigInterceptor {
timeout_config: Default::default(),
};
let _err = client
.some_operation()
.customize()
.config_override(
$name::Config::builder().timeout_config(
TimeoutConfig::builder()
.operation_attempt_timeout(operation_attempt)
.operation_timeout(operation)
.build(),
),
)
.interceptor(interceptor.clone())
.send()
.await;
let _ = dbg!(_err);
assert_eq!(
interceptor
.timeout_config
.lock()
.unwrap()
.as_ref()
.expect("timeout config not set"),
&TimeoutConfig::builder()
.operation_timeout(operation)
.operation_attempt_timeout(operation_attempt)
.read_timeout(read_timeout)
.connect_timeout(connect_timeout)
.build(),
"full set of timeouts set from all three sources."
);
// disable timeouts
let _err = client
.some_operation()
.customize()
.config_override(
$name::Config::builder().timeout_config(
TimeoutConfig::disabled(),
),
)
.interceptor(interceptor.clone())
.send()
.await;
let _ = dbg!(_err);
assert_eq!(
interceptor
.timeout_config
.lock()
.unwrap()
.as_ref()
.expect("timeout config not set"),
&TimeoutConfig::disabled(),
"timeouts disabled by config override"
);
// override one field
let _err = client
.some_operation()
.customize()
.config_override(
$name::Config::builder().timeout_config(
TimeoutConfig::builder().read_timeout(Duration::from_secs(10)).build(),
),
)
.interceptor(interceptor.clone())
.send()
.await;
let _ = dbg!(_err);
assert_eq!(
interceptor
.timeout_config
.lock()
.unwrap()
.as_ref()
.expect("timeout config not set"),
&TimeoutConfig::builder()
.read_timeout(Duration::from_secs(10))
.connect_timeout(connect_timeout)
.build(),
"read timeout overridden"
);
}
""",
"tokio_test" to writable { Attribute.TokioTest.render(this) },
)
}
}
}
}