Fast, Simple, Straightforward Test utility for async functionalities with 0 dependencies.
toml
[dev-dependencies]
awaitility = "0.1"
```rust use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; use std::time::Duration;
fn atmosttest() { let counter = Arc::new(AtomicUsize::new(5)); let tcounter = counter.clone(); std::thread::spawn(move || { while tcounter.load(Ordering::SeqCst) < 15 { tcounter.fetchadd(1, Ordering::SeqCst); } }); awaitility::atmost(Duration::from_millis(100)).until(|| counter.load(Ordering::SeqCst) > 10); }
fn atleasttest() { let counter = Arc::new(AtomicUsize::new(5)); let tcounter = counter.clone(); std::thread::spawn(move || { std::thread::sleep(Duration::frommillis(150)); while tcounter.load(Ordering::SeqCst) < 15 { tcounter.fetchadd(1, Ordering::SeqCst); } }); awaitility::atleast(Duration::frommillis(100)).always(|| counter.load(Ordering::SeqCst) < 10); } ```
```rust use awaitility::Configurable;
awaitility::atmost(Duration::frommillis(100)) .pollinterval(Duration::frommillis(45)) .describe("Becomes sunny..") ... ```
Apache License 2.0
Cause Chung (cuzfrog@gmail.com, cuzfrog@139.com)