pub struct MockExecutor { /* private fields */ }
Expand description

Executor for running tests with mocked environment

For test cases which don’t actually wait for anything in the real world.

This is the executor. It implements [Spawn] and BlockOn

It will usually be used as part of a MockRuntime.

Restricted environment

Tests run with this executor must not attempt to block on anything “outside”: every future that anything awaits must (eventually) be woken directly by some other task in the same test case.

(By directly we mean that the Waker::wake call is made by that waking future, before that future itself awaits anything.)

Panics

This executor will malfunction or panic if reentered.

Implementations§

source§

impl MockExecutor

source

pub fn new() -> Self

Make a MockExecutor with default parameters

source

pub fn with_scheduling(scheduling: SchedulingPolicy) -> Self

Make a MockExecutor with a specific SchedulingPolicy

source§

impl MockExecutor

source

pub fn spawn_identified( &self, desc: impl Display, fut: impl Future<Output = ()> + Send + 'static ) -> impl Debug + Clone + Send + 'static

Spawn a task and return something to identify it

desc should Display as some kind of short string (ideally without spaces) and will be used in the Debug impl and trace log messages from MockExecutor.

The returned value is an opaque task identifier which is very cheap to clone and which can be used by the caller in debug logging, if it’s desired to correlate with the debug output from MockExecutor. Most callers will want to ignore it.

This method is infalliable. (The MockExecutor cannot be shut down.)

source§

impl MockExecutor

source

pub fn progress_until_stalled(&self) -> impl Future<Output = ()>

Run tasks in the current executor until every other task is waiting

Panics

Might malfunction or panic if more than one such call is running at once.

(Ie, you must .await or drop the returned Future before calling this method again.)

Must be called and awaited within a future being run by self.

Trait Implementations§

source§

impl BlockOn for MockExecutor

source§

fn block_on<F>(&self, fut: F) -> F::Outputwhere F: Future,

Run fut to completion, synchronously

Panics

Might malfunction or panic if:

  • The provided future doesn’t complete (without externally blocking), but instead waits for something.

  • The MockExecutor is reentered. (Eg, block_on is reentered.)

source§

impl Clone for MockExecutor

source§

fn clone(&self) -> MockExecutor

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for MockExecutor

source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for MockExecutor

source§

fn default() -> MockExecutor

Returns the “default value” for a type. Read more
source§

impl Spawn for MockExecutor

source§

fn spawn_obj(&self, future: FutureObj<'static, ()>) -> Result<(), SpawnError>

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

fn status(&self) -> Result<(), SpawnError>

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

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

§

impl<Sp> SpawnExt for Spwhere Sp: Spawn + ?Sized,

§

fn spawn<Fut>(&self, future: Fut) -> Result<(), SpawnError>where Fut: Future<Output = ()> + Send + 'static,

Available on crate feature alloc only.
Spawns a task that polls the given future with output () to completion. Read more
§

fn spawn_with_handle<Fut>( &self, future: Fut ) -> Result<RemoteHandle<<Fut as Future>::Output>, SpawnError>where Fut: Future + Send + 'static, <Fut as Future>::Output: Send,

Available on crate features channel and std only.
Spawns a task that polls the given future to completion and returns a future that resolves to the spawned future’s output. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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