1 + | /*
|
2 + | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
3 + | * SPDX-License-Identifier: Apache-2.0
|
4 + | */
|
5 + |
|
6 + | //! Integration tests proving that retries are enabled by default with BehaviorVersion::v2025_01_17
|
7 + | //! and disabled by default with older behavior versions.
|
8 + |
|
9 + | use aws_sdk_s3::config::{Credentials, Region, SharedAsyncSleep};
|
10 + | use aws_sdk_s3::Config;
|
11 + | use aws_smithy_async::rt::sleep::TokioSleep;
|
12 + | use aws_smithy_http_client::test_util::infallible_client_fn;
|
13 + | use aws_smithy_runtime_api::client::behavior_version::BehaviorVersion;
|
14 + | use aws_smithy_types::body::SdkBody;
|
15 + | use std::sync::atomic::{AtomicU32, Ordering};
|
16 + | use std::sync::Arc;
|
17 + |
|
18 + | /// Test that retries are enabled by default with BehaviorVersion::v2025_01_17.
|
19 + | #[tokio::test]
|
20 + | #[allow(deprecated)]
|
21 + | async fn retries_enabled_by_default_with_v2025_01_17() {
|
22 + | let call_count = Arc::new(AtomicU32::new(0));
|
23 + | let call_count_clone = call_count.clone();
|
24 + |
|
25 + | let http_client = infallible_client_fn(move |_req| {
|
26 + | let count = call_count_clone.fetch_add(1, Ordering::SeqCst);
|
27 + | if count < 2 {
|
28 + | // Return 500 for first 2 attempts
|
29 + | http_1x::Response::builder()
|
30 + | .status(500)
|
31 + | .body(SdkBody::from("Internal Server Error"))
|
32 + | .unwrap()
|
33 + | } else {
|
34 + | // Return success on 3rd attempt
|
35 + | http_1x::Response::builder()
|
36 + | .status(200)
|
37 + | .body(SdkBody::from(
|
38 + | r#"<?xml version="1.0" encoding="UTF-8"?>
|
39 + | <ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
40 + | <Buckets></Buckets>
|
41 + | <Owner>
|
42 + | <ID>test-owner</ID>
|
43 + | <DisplayName>test</DisplayName>
|
44 + | </Owner>
|
45 + | </ListAllMyBucketsResult>"#,
|
46 + | ))
|
47 + | .unwrap()
|
48 + | }
|
49 + | });
|
50 + |
|
51 + | let config = Config::builder()
|
52 + | .behavior_version(BehaviorVersion::v2025_01_17())
|
53 + | .region(Region::new("us-east-1"))
|
54 + | .credentials_provider(Credentials::for_tests())
|
55 + | .sleep_impl(SharedAsyncSleep::new(TokioSleep::new()))
|
56 + | .http_client(http_client)
|
57 + | .build();
|
58 + |
|
59 + | let client = aws_sdk_s3::Client::from_conf(config);
|
60 + |
|
61 + | // This should succeed after 2 retries
|
62 + | let result = client.list_buckets().send().await;
|
63 + |
|
64 + | if let Err(e) = &result {
|
65 + | eprintln!("Error: {:?}", e);
|
66 + | }
|
67 + |
|
68 + | assert!(
|
69 + | result.is_ok(),
|
70 + | "Request should succeed after retries with BehaviorVersion::v2025_01_17"
|
71 + | );
|
72 + |
|
73 + | // Verify 3 requests were made (1 initial + 2 retries)
|
74 + | assert_eq!(
|
75 + | call_count.load(Ordering::SeqCst),
|
76 + | 3,
|
77 + | "Should have made 3 requests (1 initial + 2 retries)"
|
78 + | );
|
79 + | }
|
80 + |
|
81 + | /// Test that retries are disabled by default with older behavior versions.
|
82 + | #[tokio::test]
|
83 + | #[allow(deprecated)]
|
84 + | async fn retries_disabled_by_default_with_v2024_03_28() {
|
85 + | let call_count = Arc::new(AtomicU32::new(0));
|
86 + | let call_count_clone = call_count.clone();
|
87 + |
|
88 + | let http_client = infallible_client_fn(move |_req| {
|
89 + | call_count_clone.fetch_add(1, Ordering::SeqCst);
|
90 + | // Always return 500
|
91 + | http_1x::Response::builder()
|
92 + | .status(500)
|
93 + | .body(SdkBody::from("Internal Server Error"))
|
94 + | .unwrap()
|
95 + | });
|
96 + |
|
97 + | let config = Config::builder()
|
98 + | .behavior_version(BehaviorVersion::v2024_03_28())
|
99 + | .region(Region::new("us-east-1"))
|
100 + | .credentials_provider(Credentials::for_tests())
|
101 + | .sleep_impl(SharedAsyncSleep::new(TokioSleep::new()))
|
102 + | .http_client(http_client)
|
103 + | .build();
|
104 + |
|
105 + | let client = aws_sdk_s3::Client::from_conf(config);
|
106 + |
|
107 + | // This should fail immediately without retries
|
108 + | let result = client.list_buckets().send().await;
|
109 + |
|
110 + | assert!(
|
111 + | result.is_err(),
|
112 + | "Request should fail immediately without retries with BehaviorVersion::v2024_03_28"
|
113 + | );
|
114 + |
|
115 + | // Verify only 1 request was made (no retries)
|
116 + | assert_eq!(
|
117 + | call_count.load(Ordering::SeqCst),
|
118 + | 1,
|
119 + | "Should have made only 1 request (no retries)"
|
120 + | );
|
121 + | }
|