Skip to content

Commit

Permalink
Fix tiny_map from_iter where one operation was being dropped (#2733)
Browse files Browse the repository at this point in the history
15th operation was being dropped when iterator was being read into a
TinyMap

The 15th operation was being dropped when the if statement was caught
because the operation had been popped of the iterator but hadn't been
added to the vec of operations before the two iterators were being
chained and collected into a

Added unit tests that reproduced the issue and verified that the issue
is fixed

<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
- [ ] I have updated `CHANGELOG.next.toml` if I made changes to the AWS
SDK, generated SDK code, or SDK runtime crates

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

Co-authored-by: Thor Bjorgvinsson <[email protected]>
  • Loading branch information
drganjoo and Thor-Bjorgvinsson authored May 30, 2023
1 parent e3c65ff commit f0fe96a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
# message = "Fix typos in module documentation for generated crates"
# references = ["smithy-rs#920"]
# meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"}
# author = "rcoh"
# author = "rcoh"
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

0 comments on commit f0fe96a

Please sign in to comment.