pub struct ScriptedTimer(/* private fields */);Expand description
The app’s clock for a test that pins a deadline without waiting for it: no sleep it hands out
ends until advance has moved the clock past it. Each live sleep is counted
by its length, so a test asks whether the code under test is waiting on a deadline of a given
length (live) and whether it stopped waiting. A length named to
refuse is timed as a runtime that has shut down times it.
Implementations§
Source§impl ScriptedTimer
impl ScriptedTimer
Sourcepub fn new() -> ScriptedTimer
pub fn new() -> ScriptedTimer
A clock at zero with no sleeps live and nothing refused.
Sourcepub fn advance(&self, by: Duration)
pub fn advance(&self, by: Duration)
Moves the clock forward and wakes every sleep waiting on it; one whose deadline is now behind the clock ends on its next poll.
Sourcepub fn live(&self, length: Duration) -> usize
pub fn live(&self, length: Duration) -> usize
The sleeps of exactly length that exist and have not been dropped.
Sourcepub fn pending_at(&self, length: Duration) -> Option<Duration>
pub fn pending_at(&self, length: Duration) -> Option<Duration>
The clock time, as elapsed reads it, at which a sleep of exactly
length last answered Pending; None if none has. A value equal to elapsed() means the
sleep has seen the latest advance and not ended on it: a test waits on that to know the code
under test observed the clock short of its deadline.
Sourcepub fn refuse(&self, length: Duration)
pub fn refuse(&self, length: Duration)
From this call on, a sleep of exactly length is answered as a runtime that has shut down
answers it: sleep ends at once and try_sleep answers Err(Refused). Other lengths keep
their script, so a bound of another length the code under test also arms stays pending.
Trait Implementations§
Source§impl Clone for ScriptedTimer
impl Clone for ScriptedTimer
Source§impl Default for ScriptedTimer
impl Default for ScriptedTimer
Source§impl Timer for ScriptedTimer
impl Timer for ScriptedTimer
Source§fn sleep(&self, d: Duration) -> BoxFuture<'static, ()>
fn sleep(&self, d: Duration) -> BoxFuture<'static, ()>
d has passed, or at once on a clock whose runtime has shut down, before the
sleep or during it. try_sleep tells the two ends apart.fn now(&self) -> Instant
Source§fn try_sleep(&self, d: Duration) -> BoxFuture<'static, Result<(), Refused>>
fn try_sleep(&self, d: Duration) -> BoxFuture<'static, Result<(), Refused>>
sleep, answering Err(Refused) when the clock’s runtime has shut down, before the sleep
or during it. Code that would otherwise act on a deadline it can no longer keep reads this.
A clock that cannot shut down answers sleep’s end as Ok. A wrapper forwards this to the
clock it wraps, as it forwards sleep: answering Ok there drops that clock’s refusal.