Skip to content

Commit 5126a61

Browse files
Thor-Bjorgvinssondavid-perezdrganjoo
authored
Fix tiny_map from_iter where one operation was being dropped (#2733)
## Motivation and Context 15th operation was being dropped when iterator was being read into a TinyMap ## Description 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 ## Testing Added unit tests that reproduced the issue and verified that the issue is fixed ## Checklist <!--- 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: david-perez <d@vidp.dev> Co-authored-by: Fahad Zubair <fahadzubair@gmail.com>
1 parent ec874d5 commit 5126a61

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

CHANGELOG.next.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
# meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"}
1212
# author = "rcoh"
1313

14+
[[smithy-rs]]
15+
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."
16+
author = "thor-bjorgvinsson"
17+
references = ["smithy-rs#2733"]
18+
meta = { "breaking" = false, "tada" = false, "bug" = true, "target" ="server" }
19+
1420
[[aws-sdk-rust]]
1521
message = "Remove native-tls and add a migration guide."
1622
author = "82marbag"

rust-runtime/aws-smithy-http-server/src/routing/tiny_map.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ where
7878

7979
// Populate the `Vec`
8080
while let Some((index, pair)) = iter.next() {
81+
vec.push(pair);
82+
8183
// If overflow `CUTOFF` then return a `HashMap` instead
8284
if index == CUTOFF {
8385
let inner = TinyMapInner::HashMap(vec.into_iter().chain(iter.map(|(_, pair)| pair)).collect());
8486
return TinyMap { inner };
8587
}
86-
87-
vec.push(pair);
8888
}
8989

9090
TinyMap {
@@ -158,19 +158,25 @@ mod tests {
158158
#[test]
159159
fn get_small_success() {
160160
let tiny_map: TinyMap<_, _, CUTOFF> = SMALL_VALUES.into_iter().collect();
161-
assert_eq!(tiny_map.get("a"), Some(&0))
161+
SMALL_VALUES.into_iter().for_each(|(op, val)| {
162+
assert_eq!(tiny_map.get(op), Some(&val));
163+
});
162164
}
163165

164166
#[test]
165167
fn get_medium_success() {
166168
let tiny_map: TinyMap<_, _, CUTOFF> = MEDIUM_VALUES.into_iter().collect();
167-
assert_eq!(tiny_map.get("d"), Some(&3))
169+
MEDIUM_VALUES.into_iter().for_each(|(op, val)| {
170+
assert_eq!(tiny_map.get(op), Some(&val));
171+
});
168172
}
169173

170174
#[test]
171175
fn get_large_success() {
172176
let tiny_map: TinyMap<_, _, CUTOFF> = LARGE_VALUES.into_iter().collect();
173-
assert_eq!(tiny_map.get("h"), Some(&7))
177+
LARGE_VALUES.into_iter().for_each(|(op, val)| {
178+
assert_eq!(tiny_map.get(op), Some(&val));
179+
});
174180
}
175181

176182
#[test]

0 commit comments

Comments
 (0)