azure_core/sleep/
mod.rs

1#[cfg(not(feature = "tokio-sleep"))]
2mod thread;
3
4#[cfg(not(feature = "tokio-sleep"))]
5pub use self::thread::{sleep, Sleep};
6
7#[cfg(feature = "tokio-sleep")]
8pub use tokio::time::{sleep, Sleep};
9
10// Unit tests
11#[cfg(test)]
12mod tests {
13
14    /// Basic test that launches 10k futures and waits for them to complete
15    /// Has a high chance of failing if there is a race condition in sleep method
16    /// Runs quickly otherwise
17    #[cfg(not(feature = "tokio-sleep"))]
18    #[tokio::test]
19    async fn test_timeout() {
20        use super::*;
21        use std::time::Duration;
22        use tokio::task::JoinSet;
23
24        let mut join_set = JoinSet::default();
25        let total = 10000;
26        for _i in 0..total {
27            join_set.spawn(async move {
28                sleep(Duration::from_millis(10)).await;
29            });
30        }
31
32        loop {
33            let res =
34                tokio::time::timeout(std::time::Duration::from_secs(10), join_set.join_next())
35                    .await;
36            assert!(res.is_ok());
37            if let Ok(None) = res {
38                break;
39            }
40        }
41    }
42}