From aa7fc0271b526f41ace297a6576b775bcd410c06 Mon Sep 17 00:00:00 2001 From: Julian Kovacek Date: Fri, 17 Nov 2023 13:58:49 +1100 Subject: [PATCH] 7.0.1 (#184) * fix: don't panic when jitter is 0 --- src/utils.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/utils.rs b/src/utils.rs index a65befa9..7c33117a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -565,7 +565,11 @@ where } pub fn add_jitter(delay: u64, jitter: u32) -> u64 { - delay.saturating_add(rand::thread_rng().gen_range(0 .. jitter as u64)) + if jitter == 0 { + delay + } else { + delay.saturating_add(rand::thread_rng().gen_range(0 .. jitter as u64)) + } } pub fn into_redis_map(mut iter: I) -> Result, RedisError> @@ -832,6 +836,11 @@ mod tests { RedisValue::Array(v) } + #[test] + fn should_not_panic_with_zero_jitter() { + assert_eq!(add_jitter(10, 0), 10); + } + #[test] fn should_flatten_xread_example() { // 127.0.0.1:6379> xread count 2 streams foo bar 1643479648480-0 1643479834990-0