Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tiny_map from_iter where one operation was being dropped #2733

Merged
merged 3 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
# meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"}
# author = "rcoh"

[[smithy-rs]]
message = "Fix bug in AWS JSON 1.x routers where, if a service had more than 14 operations, the router was created without the route for the 15th operation."
author = "thor-bjorgvinsson"
references = ["smithy-rs#2733"]
meta = { "breaking" = false, "tada" = false, "bug" = true, "target" ="server" }

[[aws-sdk-rust]]
message = "Remove native-tls and add a migration guide."
author = "82marbag"
Expand Down
16 changes: 11 additions & 5 deletions rust-runtime/aws-smithy-http-server/src/routing/tiny_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ where

// Populate the `Vec`
while let Some((index, pair)) = iter.next() {
vec.push(pair);

// If overflow `CUTOFF` then return a `HashMap` instead
if index == CUTOFF {
let inner = TinyMapInner::HashMap(vec.into_iter().chain(iter.map(|(_, pair)| pair)).collect());
return TinyMap { inner };
}

vec.push(pair);
}

TinyMap {
Expand Down Expand Up @@ -158,19 +158,25 @@ mod tests {
#[test]
fn get_small_success() {
let tiny_map: TinyMap<_, _, CUTOFF> = SMALL_VALUES.into_iter().collect();
assert_eq!(tiny_map.get("a"), Some(&0))
SMALL_VALUES.into_iter().for_each(|(op, val)| {
assert_eq!(tiny_map.get(op), Some(&val));
});
}

#[test]
fn get_medium_success() {
let tiny_map: TinyMap<_, _, CUTOFF> = MEDIUM_VALUES.into_iter().collect();
assert_eq!(tiny_map.get("d"), Some(&3))
MEDIUM_VALUES.into_iter().for_each(|(op, val)| {
assert_eq!(tiny_map.get(op), Some(&val));
});
}

#[test]
fn get_large_success() {
let tiny_map: TinyMap<_, _, CUTOFF> = LARGE_VALUES.into_iter().collect();
assert_eq!(tiny_map.get("h"), Some(&7))
LARGE_VALUES.into_iter().for_each(|(op, val)| {
assert_eq!(tiny_map.get(op), Some(&val));
});
}

#[test]
Expand Down