Struct tor_rtmock::task::MockExecutor
source · 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
impl MockExecutor
sourcepub fn with_scheduling(scheduling: SchedulingPolicy) -> Self
pub fn with_scheduling(scheduling: SchedulingPolicy) -> Self
Make a MockExecutor with a specific SchedulingPolicy
source§impl MockExecutor
impl MockExecutor
sourcepub fn spawn_identified(
&self,
desc: impl Display,
fut: impl Future<Output = ()> + Send + 'static
) -> impl Debug + Clone + Send + 'static
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
impl MockExecutor
sourcepub fn progress_until_stalled(&self) -> impl Future<Output = ()>
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
impl BlockOn for MockExecutor
source§fn block_on<F>(&self, fut: F) -> F::Outputwhere
F: Future,
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
MockExecutoris reentered. (Eg,block_onis reentered.)
source§impl Clone for MockExecutor
impl Clone for MockExecutor
source§fn clone(&self) -> MockExecutor
fn clone(&self) -> MockExecutor
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for MockExecutor
impl Debug for MockExecutor
source§impl Default for MockExecutor
impl Default for MockExecutor
source§fn default() -> MockExecutor
fn default() -> MockExecutor
Auto Trait Implementations§
impl RefUnwindSafe for MockExecutor
impl Send for MockExecutor
impl Sync for MockExecutor
impl Unpin for MockExecutor
impl UnwindSafe for MockExecutor
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<Sp> SpawnExt for Spwhere
Sp: Spawn + ?Sized,
impl<Sp> SpawnExt for Spwhere Sp: Spawn + ?Sized,
§fn spawn<Fut>(&self, future: Fut) -> Result<(), SpawnError>where
Fut: Future<Output = ()> + Send + 'static,
fn spawn<Fut>(&self, future: Fut) -> Result<(), SpawnError>where Fut: Future<Output = ()> + Send + 'static,
alloc only.() 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,
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,
channel and std only.