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

Create a new MockSleepProvider, starting at a given wall-clock time.

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.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

A future returned by SleepProvider::sleep()

Return a future that will be ready after duration has elapsed. Read more

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

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

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

Return the SleepProvider’s view of the current instant. Read more

Return the SleepProvider’s view of the current wall-clock time. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Wrap a Future with a timeout. Read more

Pause until the wall-clock is at when or later, trying to recover from clock jumps. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more