use mudssky_utils::async_utils::*;
use std::time::{Duration, Instant};
#[tokio::test]
async fn test_sleep_async_basic() {
let start = Instant::now();
sleep_async(100).await;
let elapsed = start.elapsed();
assert!(elapsed >= Duration::from_millis(50));
assert!(elapsed <= Duration::from_millis(200));
}
#[tokio::test]
async fn test_sleep_async_zero() {
let start = Instant::now();
sleep_async(0).await;
let elapsed = start.elapsed();
assert!(elapsed <= Duration::from_millis(50));
}
#[tokio::test]
async fn test_sleep_async_longer_duration() {
let start = Instant::now();
sleep_async(500).await;
let elapsed = start.elapsed();
assert!(elapsed >= Duration::from_millis(400));
assert!(elapsed <= Duration::from_millis(600));
}
#[tokio::test]
async fn test_sleep_async_multiple_calls() {
let start = Instant::now();
sleep_async(50).await;
sleep_async(50).await;
sleep_async(50).await;
let elapsed = start.elapsed();
assert!(elapsed >= Duration::from_millis(100));
assert!(elapsed <= Duration::from_millis(250));
}
#[tokio::test]
async fn test_sleep_async_concurrent() {
let start = Instant::now();
let (_, _, _) = tokio::join!(sleep_async(100), sleep_async(100), sleep_async(100));
let elapsed = start.elapsed();
assert!(elapsed >= Duration::from_millis(50));
assert!(elapsed <= Duration::from_millis(200));
}
#[tokio::test]
async fn test_sleep_async_large_value() {
let start = Instant::now();
sleep_async(1).await; let elapsed = start.elapsed();
assert!(elapsed <= Duration::from_millis(50));
}