Struct tor_rtmock::time::MockSleepProvider
source · [−]pub struct MockSleepProvider { /* private fields */ }
Expand description
A dummy SleepProvider
instance for testing.
The MockSleepProvider ignores the current time, and instead keeps
its own view of the current Instant
and SystemTime
. You
can advance them in-step by calling advance()
, and you can simulate
jumps in the system clock by calling jump()
.
This is not for production use.
Implementations
sourceimpl MockSleepProvider
impl MockSleepProvider
sourcepub fn new(wallclock: SystemTime) -> Self
pub fn new(wallclock: SystemTime) -> Self
Create a new MockSleepProvider, starting at a given wall-clock time.
sourcepub async fn advance(&self, dur: Duration)
pub async fn advance(&self, dur: Duration)
Advance the simulated timeline forward by dur
.
Calling this function will wake any pending futures as appropriate, and yield to the scheduler so they get a chance to run.
Limitations
This function advances time in one big step. We might instead want to advance in small steps and make sure that each step’s futures can get run before the ones scheduled to run after it.
sourcepub fn jump_to(&self, new_wallclock: SystemTime)
pub fn jump_to(&self, new_wallclock: SystemTime)
Simulate a discontinuity in the system clock, by jumping to
new_wallclock
.
Panics
Panics if we have already panicked while holding the lock on the internal timer state, and the lock is poisoned.
Trait Implementations
sourceimpl Clone for MockSleepProvider
impl Clone for MockSleepProvider
sourcefn clone(&self) -> MockSleepProvider
fn clone(&self) -> MockSleepProvider
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for MockSleepProvider
impl Debug for MockSleepProvider
sourceimpl SleepProvider for MockSleepProvider
impl SleepProvider for MockSleepProvider
type SleepFuture = Sleeping
type SleepFuture = Sleeping
A future returned by SleepProvider::sleep()
sourcefn sleep(&self, duration: Duration) -> Self::SleepFuture
fn sleep(&self, duration: Duration) -> Self::SleepFuture
Return a future that will be ready after duration
has
elapsed. Read more
sourcefn block_advance<T: Into<String>>(&self, reason: T)
fn block_advance<T: Into<String>>(&self, reason: T)
Signify that a test running under mock time shouldn’t advance time yet, with a given unique reason string. This is useful for making sure (mock) time doesn’t advance while things that might require some (real-world) time to complete do so, such as spawning a task on another thread. Read more
sourcefn release_advance<T: Into<String>>(&self, reason: T)
fn release_advance<T: Into<String>>(&self, reason: T)
Signify that the reason to withhold time advancing provided in a call to block_advance
no
longer exists, and it’s fine to move time forward if nothing else is blocking advances. Read more
sourcefn allow_one_advance(&self, dur: Duration)
fn allow_one_advance(&self, dur: Duration)
Allow a test running under mock time to advance time by the provided duration, even if the
above block_advance
API has been used. Read more
sourcefn wallclock(&self) -> SystemTime
fn wallclock(&self) -> SystemTime
Return the SleepProvider’s view of the current wall-clock time. Read more
Auto Trait Implementations
impl RefUnwindSafe for MockSleepProvider
impl Send for MockSleepProvider
impl Sync for MockSleepProvider
impl Unpin for MockSleepProvider
impl UnwindSafe for MockSleepProvider
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> SleepProviderExt for T where
T: SleepProvider,
impl<T> SleepProviderExt for T where
T: SleepProvider,
sourcefn timeout<F>(
&self,
duration: Duration,
future: F
) -> Timeout<F, Self::SleepFuture> where
F: Future,
fn timeout<F>(
&self,
duration: Duration,
future: F
) -> Timeout<F, Self::SleepFuture> where
F: Future,
sourcefn sleep_until_wallclock(
&self,
when: SystemTime
) -> SleepUntilWallclock<'_, Self>
fn sleep_until_wallclock(
&self,
when: SystemTime
) -> SleepUntilWallclock<'_, Self>
Pause until the wall-clock is at when
or later, trying to
recover from clock jumps. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more