1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//! # Awaitility for Rust
//! Fast, Simple, Straightforward Test utility for async functionalities.
//! ## Basic Usage
//! ```rust
//! # use std::time::Duration;
//! # fn test_something_is_true() -> bool { true }
//! awaitility::at_most(Duration::from_millis(100)).until(|| {test_something_is_true()});
//! awaitility::at_least(Duration::from_millis(50)).always(|| {test_something_is_true()});
//! awaitility::at_most(Duration::from_millis(100)).until_no_panic(|| {assert_eq!(1, 1)});
//! // ...
//! ```
//! ## Examples
//! ```rust
//! use std::sync::atomic::{AtomicUsize, Ordering};
//! use std::sync::Arc;
//! use std::time::Duration;
//!
//! fn at_most_test() {
//! let counter = Arc::new(AtomicUsize::new(5));
//! let tcounter = counter.clone();
//! std::thread::spawn(move || {
//! while tcounter.load(Ordering::SeqCst) < 15 {
//! tcounter.fetch_add(1, Ordering::SeqCst);
//! }
//! });
//! awaitility::at_most(Duration::from_millis(100)).until(|| counter.load(Ordering::SeqCst) > 10);
//! }
//! ```
//! ### Async function
//! ```rust
//! #[tokio::test]
//! async fn always_async_test() {
//! super::at_least(Duration::from_millis(100)).always_async(|| async {
//! 1 < 2
//! }).await;
//! }
//! ```
//!
//! ### Return result
//! ```rust
//! # use std::time::Duration;
//! let res = awaitility::new().set_return().at_most(Duration::from_millis(10)).until(|| 1 > 2).result();
//! assert!(res.is_err());
//! ```
//! ## Config
//! ```rust
//! # use std::time::Duration;
//! awaitility::at_most(Duration::from_millis(100))
//! .poll_interval(Duration::from_millis(45))
//! .describe("Becomes sunny..")
//! .until(|| 2 > 1);
//! ```
//!
//! ### Share configured instance
//! ```rust
//! use std::time::Duration;
//!
//! let aw = awaitility::new().poll_interval(Duration::from_millis(45));
//! aw.at_least(Duration::from_millis(10)).always(|| 2 > 1);
//! aw.at_least(Duration::from_millis(10)).once(|| 2 > 1);
//! ```
//! Further configs made after `at_least` will not be reflected on instance `aw`.
use Duration;
/// Create an at-most wait directive with default configs.
/// Create an at-least wait directive with default configs.
/// Create an awaitility instance with shared configs.