Skip to content

Commit

Permalink
Add unit tests to ExponentialBackoff
Browse files Browse the repository at this point in the history
  • Loading branch information
faern committed Oct 3, 2023
1 parent 0e38a3c commit 62e9694
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/exponential_backoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,29 @@ impl ExponentialBackoff {
delay
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn correct_delays() {
let mut backoff =
ExponentialBackoff::new(Duration::from_millis(60), Duration::from_millis(300));
assert_eq!(backoff.next_delay(), Duration::from_millis(60));
assert_eq!(backoff.next_delay(), Duration::from_millis(120));
assert_eq!(backoff.next_delay(), Duration::from_millis(240));
assert_eq!(backoff.next_delay(), Duration::from_millis(300));
assert_eq!(backoff.next_delay(), Duration::from_millis(300));
}

#[test]
fn reset() {
let mut backoff =
ExponentialBackoff::new(Duration::from_millis(60), Duration::from_millis(300));
assert_eq!(backoff.next_delay(), Duration::from_millis(60));
backoff.reset();
assert_eq!(backoff.next_delay(), Duration::from_millis(60));
assert_eq!(backoff.next_delay(), Duration::from_millis(120));
}
}

0 comments on commit 62e9694

Please sign in to comment.