File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed
Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change 8282 /// - `max` == 0
8383 /// - `jitter` < `0.0`
8484 /// - `jitter` > `100.0`
85- /// - `jitter` is not finite
85+ /// - `jitter` is NaN
8686 pub fn new (
8787 min : time:: Duration ,
8888 max : time:: Duration ,
@@ -101,8 +101,8 @@ where
101101 if jitter > 100.0 {
102102 return Err ( InvalidBackoff ( "jitter must not be greater than 100" ) ) ;
103103 }
104- if ! jitter. is_finite ( ) {
105- return Err ( InvalidBackoff ( "jitter must be finite " ) ) ;
104+ if jitter. is_nan ( ) {
105+ return Err ( InvalidBackoff ( "jitter must not be NaN " ) ) ;
106106 }
107107
108108 Ok ( ExponentialBackoffMaker {
@@ -260,4 +260,20 @@ mod tests {
260260 }
261261 }
262262 }
263+
264+ #[ test]
265+ fn jitter_must_be_finite ( ) {
266+ let min = time:: Duration :: from_millis ( 0 ) ;
267+ let max = time:: Duration :: from_millis ( 1 ) ;
268+ let rng = HasherRng :: default ( ) ;
269+
270+ for n in [ f64:: INFINITY , f64:: NEG_INFINITY , f64:: NAN ] {
271+ let result = ExponentialBackoffMaker :: new ( min, max, n, rng. clone ( ) ) ;
272+ assert ! (
273+ matches!( result, Err ( InvalidBackoff ( _) ) ) ,
274+ "{} should be an invalid jitter" ,
275+ n
276+ ) ;
277+ }
278+ }
263279}
You can’t perform that action at this time.
0 commit comments