Skip to content

Commit

Permalink
Use time::pause on duration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomWright committed Oct 22, 2024
1 parent 218f75c commit 5cb05e7
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/limiter/rejection_delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Limiter for RejectionDelay {
mod tests {
use std::time::Duration;

use tokio::time::Instant;
use tokio::time::{self, Instant};

use crate::assert_elapsed;
use crate::{
Expand All @@ -68,7 +68,9 @@ mod tests {

#[tokio::test]
async fn on_rejection_delay_acquire() {
let delay = Duration::from_millis(50);
time::pause();

let delay = Duration::from_millis(5000);

let limiter = RejectionDelay::new(delay, DefaultLimiter::new(Fixed::new(1)));

Expand All @@ -83,17 +85,19 @@ mod tests {

#[tokio::test]
async fn on_rejection_delay_acquire_timeout() {
let delay = Duration::from_millis(50);
time::pause();

let delay = Duration::from_millis(5000);

let limiter = RejectionDelay::new(delay, DefaultLimiter::new(Fixed::new(1)));

let _token = limiter.try_acquire().await.unwrap();

let before_acquire = Instant::now();
let token = limiter.acquire_timeout(Duration::ZERO).await;
let token = limiter.acquire_timeout(delay).await;

assert!(token.is_none());
assert_elapsed!(before_acquire, delay, Duration::from_millis(10));
assert_elapsed!(before_acquire, delay * 2, Duration::from_millis(10));
}

/// Assert that a given duration has elapsed since `start`, within the given tolerance.
Expand Down

0 comments on commit 5cb05e7

Please sign in to comment.