Skip to content

Commit 2c0274c

Browse files
authored
Compare query strings based on set of components in ec2 integration tests (#3859)
## Motivation and Context Avoids comparing raw strings in ec2 integration tests ## Description With a updated service model for ec2, we have run into the following test failures in its integration tests, ``` ----- paginators_handle_unset_tokens stdout ---- body did not match. left=expected, right=actual Diff < left / right > : <Action=DescribeSpotPriceHistory&Version=2016-11-15&·[1;48;5;52;31mAvailabilityZone=eu-north-1a&InstanceType.1=g5.48xlarge&ProductDescription.1=Linux%2FUNIX >Action=DescribeSpotPriceHistory&Version=2016-11-15&InstanceType.1=g5.48xlarge&ProductDescription.1=Linux%2FUNIX·[1;48;5;22;32m&AvailabilityZone=eu-north-1a thread 'paginators_handle_unset_tokens' panicked at sdk/aws-smithy-runtime/src/client/http/test_util/replay.rs:98:43: ---- paginators_handle_empty_tokens stdout ---- body did not match. left=expected, right=actual Diff < left / right > : <Action=DescribeSpotPriceHistory&Version=2016-11-15&·[1;48;5;52;31mAvailabilityZone=eu-north-1a&InstanceType.1=g5.48xlarge&ProductDescription.1=Linux%2FUNIX >Action=DescribeSpotPriceHistory&Version=2016-11-15&InstanceType.1=g5.48xlarge&ProductDescription.1=Linux%2FUNIX·[1;48;5;22;32m&AvailabilityZone=eu-north-1a thread 'paginators_handle_empty_tokens' panicked at sdk/aws-smithy-runtime/src/client/http/test_util/replay.rs:98:43: ``` We don't know exactly how a generated ec2 SDK built up query strings in a different order from what it is today, but whatever the root cause is, the ultimate fix remains the same. Comparing raw query strings can be unreliable, so this PR will fix that by comparing sets of strings derived from query strings. ## Testing Ran the edited tests against the generated ec2 SDK in question and it passed (without this PR, it did fail). ---- _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 4d0b838 commit 2c0274c

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

aws/sdk/integration-tests/ec2/tests/paginators.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55

66
use aws_runtime::user_agent::test_util::assert_ua_contains_metric_values;
77
use aws_sdk_ec2::{config::Credentials, config::Region, types::InstanceType, Client, Config};
8-
use aws_smithy_runtime::client::http::test_util::{
9-
capture_request, ReplayEvent, StaticReplayClient,
10-
};
8+
use aws_smithy_runtime::client::http::test_util::capture_request;
119
use aws_smithy_runtime_api::client::http::HttpClient;
1210
use aws_smithy_types::body::SdkBody;
11+
use std::collections::HashSet;
1312

1413
fn stub_config(http_client: impl HttpClient + 'static) -> Config {
1514
Config::builder()
@@ -19,28 +18,29 @@ fn stub_config(http_client: impl HttpClient + 'static) -> Config {
1918
.build()
2019
}
2120

21+
fn validate_query_string(expected: &str, actual: &str) {
22+
let expected = expected.split('&').collect::<HashSet<&str>>();
23+
let actual = actual.split('&').collect::<HashSet<&str>>();
24+
assert_eq!(expected, actual);
25+
assert_eq!(expected.len(), actual.len());
26+
}
27+
2228
/// See https://github.com/awslabs/aws-sdk-rust/issues/391
2329
///
2430
/// EC2 replies with `<nextToken></nextToken>` which our XML parser parses as empty string and not "none"
2531
#[tokio::test]
2632
async fn paginators_handle_empty_tokens() {
27-
let request= "Action=DescribeSpotPriceHistory&Version=2016-11-15&AvailabilityZone=eu-north-1a&InstanceType.1=g5.48xlarge&ProductDescription.1=Linux%2FUNIX";
2833
let response = r#"<?xml version="1.0" encoding="UTF-8"?>
2934
<DescribeSpotPriceHistoryResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
3035
<requestId>edf3e86c-4baf-47c1-9228-9a5ea09542e8</requestId>
3136
<spotPriceHistorySet/>
3237
<nextToken></nextToken>
3338
</DescribeSpotPriceHistoryResponse>"#;
34-
let http_client = StaticReplayClient::new(vec![ReplayEvent::new(
35-
http::Request::builder()
36-
.uri("https://ec2.us-east-1.amazonaws.com/")
37-
.body(request.into())
38-
.unwrap(),
39-
http::Response::builder()
40-
.status(200)
41-
.body(SdkBody::from(response))
42-
.unwrap(),
43-
)]);
39+
let response = http::Response::builder()
40+
.status(200)
41+
.body(SdkBody::from(response))
42+
.unwrap();
43+
let (http_client, captured_request) = capture_request(Some(response));
4444
let client = Client::from_conf(stub_config(http_client.clone()));
4545
let instance_type = InstanceType::from("g5.48xlarge");
4646
let mut paginator = client
@@ -53,30 +53,27 @@ async fn paginators_handle_empty_tokens() {
5353
.send();
5454
let first_item = paginator.try_next().await.expect("success");
5555
assert_eq!(first_item, None);
56-
http_client.assert_requests_match(&[]);
56+
let req = captured_request.expect_request();
57+
let actual_body = std::str::from_utf8(req.body().bytes().unwrap()).unwrap();
58+
let expected_body = "Action=DescribeSpotPriceHistory&Version=2016-11-15&AvailabilityZone=eu-north-1a&InstanceType.1=g5.48xlarge&ProductDescription.1=Linux%2FUNIX";
59+
validate_query_string(expected_body, actual_body);
5760
}
5861

5962
/// See https://github.com/awslabs/aws-sdk-rust/issues/405
6063
///
6164
/// EC2 can also reply with the token truly unset which will be interpreted as `None`
6265
#[tokio::test]
6366
async fn paginators_handle_unset_tokens() {
64-
let request= "Action=DescribeSpotPriceHistory&Version=2016-11-15&AvailabilityZone=eu-north-1a&InstanceType.1=g5.48xlarge&ProductDescription.1=Linux%2FUNIX";
6567
let response = r#"<?xml version="1.0" encoding="UTF-8"?>
6668
<DescribeSpotPriceHistoryResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
6769
<requestId>edf3e86c-4baf-47c1-9228-9a5ea09542e8</requestId>
6870
<spotPriceHistorySet/>
6971
</DescribeSpotPriceHistoryResponse>"#;
70-
let http_client = StaticReplayClient::new(vec![ReplayEvent::new(
71-
http::Request::builder()
72-
.uri("https://ec2.us-east-1.amazonaws.com/")
73-
.body(request.into())
74-
.unwrap(),
75-
http::Response::builder()
76-
.status(200)
77-
.body(SdkBody::from(response))
78-
.unwrap(),
79-
)]);
72+
let response = http::Response::builder()
73+
.status(200)
74+
.body(SdkBody::from(response))
75+
.unwrap();
76+
let (http_client, captured_request) = capture_request(Some(response));
8077
let client = Client::from_conf(stub_config(http_client.clone()));
8178
let instance_type = InstanceType::from("g5.48xlarge");
8279
let mut paginator = client
@@ -89,7 +86,10 @@ async fn paginators_handle_unset_tokens() {
8986
.send();
9087
let first_item = paginator.try_next().await.expect("success");
9188
assert_eq!(first_item, None);
92-
http_client.assert_requests_match(&[]);
89+
let req = captured_request.expect_request();
90+
let actual_body = std::str::from_utf8(req.body().bytes().unwrap()).unwrap();
91+
let expected_body = "Action=DescribeSpotPriceHistory&Version=2016-11-15&AvailabilityZone=eu-north-1a&InstanceType.1=g5.48xlarge&ProductDescription.1=Linux%2FUNIX";
92+
validate_query_string(expected_body, actual_body);
9393
}
9494

9595
#[tokio::test]

0 commit comments

Comments
 (0)