-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug where paginators looped forever on empty string next token
- Loading branch information
Showing
7 changed files
with
138 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
[workspace] | ||
members = [ | ||
"dynamodb", | ||
"ec2", | ||
"iam", | ||
"kms", | ||
"polly", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "ec2-tests" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
[dev-dependencies] | ||
aws-sdk-ec2 = { path = "../../build/aws-sdk/sdk/ec2" } | ||
aws-smithy-client = { path = "../../build/aws-sdk/sdk/aws-smithy-client", features = ["test-util"]} | ||
tokio = { version = "1", features = ["full"]} | ||
http = "0.2.6" | ||
tokio-stream = "0.1.8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
|
||
use aws_sdk_ec2::{model::InstanceType, Client, Config, Credentials, Region}; | ||
use aws_smithy_client::test_connection::TestConnection; | ||
use tokio_stream::StreamExt; | ||
|
||
fn stub_config() -> Config { | ||
Config::builder() | ||
.region(Region::new("us-east-1")) | ||
.credentials_provider(Credentials::new("akid", "secret", None, None, "test")) | ||
.build() | ||
} | ||
|
||
/// See https://github.com/awslabs/aws-sdk-rust/issues/391 | ||
/// | ||
/// EC2 replies with `<nextToken></nextToken>` which our XML parser parses as empty string and not "none" | ||
#[tokio::test] | ||
async fn paginators_handle_empty_tokens() { | ||
let request= "Action=DescribeSpotPriceHistory&Version=2016-11-15&AvailabilityZone=eu-north-1a&InstanceType.1=g5.48xlarge&ProductDescription.1=Linux%2FUNIX"; | ||
let response = r#"<?xml version="1.0" encoding="UTF-8"?> | ||
<DescribeSpotPriceHistoryResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/"> | ||
<requestId>edf3e86c-4baf-47c1-9228-9a5ea09542e8</requestId> | ||
<spotPriceHistorySet/> | ||
<nextToken></nextToken> | ||
</DescribeSpotPriceHistoryResponse>"#; | ||
let conn = TestConnection::<&str>::new(vec![( | ||
http::Request::builder() | ||
.uri("https://ec2.us-east-1.amazonaws.com/") | ||
.body(request.into()) | ||
.unwrap(), | ||
http::Response::builder() | ||
.status(200) | ||
.body(response) | ||
.unwrap(), | ||
)]); | ||
let client = Client::from_conf_conn(stub_config(), conn.clone()); | ||
let instance_type = InstanceType::from("g5.48xlarge"); | ||
let mut paginator = client | ||
.describe_spot_price_history() | ||
.instance_types(instance_type) | ||
.product_descriptions("Linux/UNIX") | ||
.availability_zone("eu-north-1a") | ||
.into_paginator() | ||
.items() | ||
.send(); | ||
let first_item = paginator.try_next().await.expect("success"); | ||
assert_eq!(first_item, None); | ||
conn.assert_requests_match(&[]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters