Skip to content

Commit a27be2b

Browse files
authored
Add dynamodb retry test (#3321)
## Motivation and Context Adds a test to ensure that `ThrottlingErrors` from DynamoDB do not result in a new connection ## Checklist - no changelog ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
1 parent 7eb06bc commit a27be2b

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

aws/sdk/integration-tests/dynamodb/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ aws-sdk-dynamodb = { path = "../../build/aws-sdk/sdk/dynamodb", features = ["beh
1919
aws-smithy-async = { path = "../../build/aws-sdk/sdk/aws-smithy-async", features = ["test-util"] }
2020
aws-smithy-http = { path = "../../build/aws-sdk/sdk/aws-smithy-http" }
2121
aws-smithy-protocol-test = { path = "../../build/aws-sdk/sdk/aws-smithy-protocol-test" }
22-
aws-smithy-runtime = { path = "../../build/aws-sdk/sdk/aws-smithy-runtime", features = ["test-util"]}
22+
aws-smithy-runtime = { path = "../../build/aws-sdk/sdk/aws-smithy-runtime", features = ["test-util", "wire-mock"]}
2323
aws-smithy-runtime-api = { path = "../../build/aws-sdk/sdk/aws-smithy-runtime-api", features = ["test-util"]}
2424
aws-smithy-types = { path = "../../build/aws-sdk/sdk/aws-smithy-types", features = ["test-util"]}
2525
aws-types = { path = "../../build/aws-sdk/sdk/aws-types" }
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
use std::time::Duration;
7+
8+
use aws_credential_types::Credentials;
9+
use aws_sdk_dynamodb::types::AttributeValue;
10+
use aws_sdk_dynamodb::Client;
11+
use aws_smithy_async::rt::sleep::{SharedAsyncSleep, TokioSleep};
12+
use aws_smithy_runtime::client::http::test_util::wire::{ReplayedEvent, WireMockServer};
13+
use aws_smithy_runtime::{ev, match_events};
14+
use aws_smithy_types::retry::RetryConfig;
15+
use aws_smithy_types::timeout::TimeoutConfig;
16+
use aws_types::region::Region;
17+
use bytes::Bytes;
18+
19+
const DYNAMO_THROTTLING_RESPONSE: &str = r#"{"__type":"com.amazonaws.dynamodb.v20120810#ThrottlingException",
20+
"message":"enhance your calm"}"#;
21+
22+
const DYNAMODB_DB_SUCCESS_RESPONSE: &str = r#"{"Count":0,"Items":[],"ScannedCount":2}"#;
23+
24+
#[tokio::test]
25+
async fn test_no_reconnect_500_throttling() {
26+
assert_error_not_transient(ReplayedEvent::HttpResponse {
27+
status: 500,
28+
body: Bytes::from(DYNAMO_THROTTLING_RESPONSE),
29+
})
30+
.await
31+
}
32+
33+
#[tokio::test]
34+
async fn test_no_reconnect_429_throttling() {
35+
assert_error_not_transient(ReplayedEvent::HttpResponse {
36+
status: 429,
37+
body: Bytes::from(DYNAMO_THROTTLING_RESPONSE),
38+
})
39+
.await
40+
}
41+
42+
async fn assert_error_not_transient(error: ReplayedEvent) {
43+
let mock = WireMockServer::start(vec![
44+
error,
45+
ReplayedEvent::with_body(DYNAMODB_DB_SUCCESS_RESPONSE),
46+
])
47+
.await;
48+
49+
let config = aws_sdk_dynamodb::Config::builder()
50+
.region(Region::from_static("us-east-2"))
51+
.credentials_provider(Credentials::for_tests())
52+
.sleep_impl(SharedAsyncSleep::new(TokioSleep::new()))
53+
.endpoint_url(mock.endpoint_url())
54+
.http_client(mock.http_client())
55+
.timeout_config(
56+
TimeoutConfig::builder()
57+
.operation_attempt_timeout(Duration::from_millis(100))
58+
.build(),
59+
)
60+
.retry_config(RetryConfig::standard())
61+
.build();
62+
let client = Client::from_conf(config);
63+
let _item = client
64+
.get_item()
65+
.key("foo", AttributeValue::Bool(true))
66+
.send()
67+
.await
68+
.expect("should succeed");
69+
match_events!(ev!(dns), ev!(connect), _, ev!(http(200)))(&mock.events());
70+
}

0 commit comments

Comments
 (0)