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
//! Helpers for deterministic virtual time under Tokio paused runtimes (`SC-010`).
//!
//! Integration tests annotate `#[tokio::test(start_paused = true)]` then drive timeouts,
//! backoff, and shutdown grace timers with [`advance_test_clock`] instead of relying on wall
//! clock `sleep`.
use Future;
use Duration;
/// Quantum used by [`with_auto_clock_drive`] to march the mocked clock forward.
pub const AUTO_CLOCK_TICK: Duration = from_millis;
/// Advances the paused Tokio timer wheel by `duration`.
///
/// # Arguments
///
/// - `duration`: Virtual elapsed time applied to timers and `tokio::time::Instant::now()` in this
/// runtime.
///
/// # Returns
///
/// This asynchronous function resolves after the mocked clock jumps forward.
///
/// # Preconditions
///
/// The enclosing `#[tokio::test(start_paused = true)]` (or equivalent main) must configure a
/// paused runtime; otherwise callers should not use this helper.
///
/// # Examples
///
/// ```ignore
/// #[tokio::test(start_paused = true)]
/// async fn example() {
/// rust_supervisor::test_support::test_time::advance_test_clock(Duration::from_millis(30))
/// .await;
/// }
/// ```
pub async
/// Runs [`advance_test_clock`] in a tight loop forever until the returned join handle is aborted.
///
/// Intended for spawning alongside [`tokio::time::timeout`] wrappers in paused tests when the wrapped
/// work needs continuous virtual clock progress.
///
/// # Returns
///
/// Returns [`tokio::task::JoinHandle`] for the spawned driver task.
/// Runs `body` while concurrently stepping the mocked clock so timer-dependent work completes.
///
/// # Type parameters
///
/// - `F`: Future produced by async work under test.
///
/// # Arguments
///
/// - `body`: Async block that awaits supervisor behavior relying on Tokio timers.
///
/// # Returns
///
/// Returns the output resolved by `body`.
pub async