pub struct MockSleepRuntime<R: Runtime> { /* private fields */ }
Expand description

A wrapper Runtime that overrides the SleepProvider trait for the underlying runtime.

Implementations

Create a new runtime that wraps runtime, but overrides its view of time with a MockSleepProvider.

Return a reference to the underlying runtime.

Return a reference to the MockSleepProvider

Run a future under mock time, advancing time forward where necessary until it completes. Users of this function should read the whole of this documentation before using!

The returned future will run fut, expecting it to create Sleeping futures (as returned by MockSleepProvider::sleep() and similar functions). When all such created futures have been polled (indicating the future is waiting on them), time will be advanced in order that the first (or only) of said futures returns Ready. This process then repeats until fut returns Ready itself (as in, the returned wrapper future will wait for all created Sleeping futures to be polled, and advance time again).

Note: The above described algorithm interacts poorly with futures that spawn asynchronous background tasks, or otherwise expect work to complete in the background before time is advanced. These futures will need to make use of the SleepProvider::block_advance (and similar) APIs in order to prevent time advancing while said tasks complete; see the documentation for those APIs for more detail.

Panics

Panics if another WaitFor future is already running. (If two ran simultaneously, they would both try and advance the same mock time clock, which would be bad.)

Trait Implementations

Run future until it is ready, and return its output.

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

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

Return the SleepProvider’s view of the current wall-clock time. 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

Spawns a future that will be run to completion. Read more

Determines whether the executor is able to spawn new tasks. Read more

The type for the TCP connections returned by Self::connect().

The type for the TCP listeners returned by Self::listen().

Launch a TCP connection to a given socket address. Read more

Open a TCP listener on a given socket address.

The Connector object that this provider can return.

The type of the stream returned by that connector.

Return a TLS connector for use with this runtime.

The type of Udp Socket returned by Self::bind()

Bind a local port to send and receive packets from

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

Spawns a task that polls the given future with output () to completion. Read more

Spawns a task that polls the given future to completion and returns a future that resolves to the spawned future’s output. 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