mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-20 19:42:17 +00:00
test(utils): make retry timer assertions deterministic (#2468)
This commit is contained in:
+17
-14
@@ -172,25 +172,28 @@ pub fn is_request_error_retryable(_err: std::io::Error) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[allow(unused_imports)]
|
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use rand::RngExt;
|
use tokio::time::{Duration, timeout};
|
||||||
use std::time::UNIX_EPOCH;
|
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_retry() {
|
async fn retry_timer_yields_expected_number_of_retries() {
|
||||||
let req_retry = 10;
|
let max_retry = 3;
|
||||||
let random = rand::rng().random_range(0..=100);
|
let retry_timer = RetryTimer::new(max_retry, Duration::from_millis(1), Duration::from_millis(2), NO_JITTER, 0);
|
||||||
|
|
||||||
let mut retry_timer = RetryTimer::new(req_retry, DEFAULT_RETRY_UNIT, DEFAULT_RETRY_CAP, MAX_JITTER, random);
|
let retries = timeout(Duration::from_secs(1), retry_timer.collect::<Vec<_>>())
|
||||||
println!("retry_timer: {retry_timer:?}");
|
.await
|
||||||
while retry_timer.next().await.is_some() {
|
.expect("retry timer should complete")
|
||||||
println!(
|
.len();
|
||||||
"\ntime: {:?}",
|
|
||||||
std::time::SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis()
|
assert_eq!(retries, max_retry as usize);
|
||||||
);
|
}
|
||||||
}
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn retry_timer_finishes_immediately_when_retry_count_is_zero() {
|
||||||
|
let mut retry_timer = RetryTimer::new(0, Duration::from_millis(1), Duration::from_millis(2), NO_JITTER, 0);
|
||||||
|
|
||||||
|
assert_eq!(retry_timer.next().await, None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user