File tree Expand file tree Collapse file tree
crates/charon/src/expbackoff Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -288,4 +288,46 @@ mod tests {
288288 assert ! ( duration - expected <= Duration :: from_millis( 10 ) ) ;
289289 }
290290 }
291+
292+ #[ test]
293+ fn reset ( ) {
294+ let mut instance = ExponentialBackoffBuilder :: default ( )
295+ . with_base_delay ( Duration :: from_secs ( 1 ) )
296+ . with_multiplier ( 2.0 )
297+ . with_jitter ( 0.0 )
298+ . with_rng ( Const ( 0.0 ) )
299+ . with_max_delay ( Duration :: from_hours ( 1 ) )
300+ . build ( )
301+ . unwrap ( ) ;
302+
303+ let mut total_time = Duration :: default ( ) ;
304+
305+ // first backoff
306+ total_time += instance. backoff ( ) ;
307+ instance. tried ( ) ;
308+ assert_eq ! ( total_time, Duration :: from_secs( 1 ) ) ;
309+
310+ // second backoff
311+ total_time += instance. backoff ( ) ;
312+ instance. tried ( ) ;
313+ assert_eq ! ( total_time, Duration :: from_secs( 3 ) ) ;
314+
315+ // third backoff
316+ total_time += instance. backoff ( ) ;
317+ instance. tried ( ) ;
318+ assert_eq ! ( total_time, Duration :: from_secs( 7 ) ) ;
319+
320+ // third backoff
321+ total_time += instance. backoff ( ) ;
322+ instance. tried ( ) ;
323+ assert_eq ! ( total_time, Duration :: from_secs( 15 ) ) ;
324+
325+ // reset
326+ instance. reset ( ) ;
327+
328+ // fourth backoff
329+ total_time += instance. backoff ( ) ;
330+ instance. tried ( ) ;
331+ assert_eq ! ( total_time, Duration :: from_secs( 16 ) ) ;
332+ }
291333}
You can’t perform that action at this time.
0 commit comments