Struct tor_rtmock::MockSleepRuntime
source · [−]pub struct MockSleepRuntime<R: Runtime> { /* private fields */ }
Expand description
A wrapper Runtime that overrides the SleepProvider trait for the underlying runtime.
Implementations
sourceimpl<R: Runtime> MockSleepRuntime<R>
impl<R: Runtime> MockSleepRuntime<R>
sourcepub fn new(runtime: R) -> Self
pub fn new(runtime: R) -> Self
Create a new runtime that wraps runtime
, but overrides
its view of time with a MockSleepProvider
.
sourcepub fn mock_sleep(&self) -> &MockSleepProvider
pub fn mock_sleep(&self) -> &MockSleepProvider
Return a reference to the MockSleepProvider
sourcepub fn jump_to(&self, new_wallclock: SystemTime)
pub fn jump_to(&self, new_wallclock: SystemTime)
sourcepub fn wait_for<F: Future>(&self, fut: F) -> WaitFor<F>
pub fn wait_for<F: Future>(&self, fut: F) -> WaitFor<F>
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
sourceimpl<R: Runtime> BlockOn for MockSleepRuntime<R>
impl<R: Runtime> BlockOn for MockSleepRuntime<R>
sourceimpl<R: Clone + Runtime> Clone for MockSleepRuntime<R>
impl<R: Clone + Runtime> Clone for MockSleepRuntime<R>
sourcefn clone(&self) -> MockSleepRuntime<R>
fn clone(&self) -> MockSleepRuntime<R>
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<R: Debug + Runtime> Debug for MockSleepRuntime<R>
impl<R: Debug + Runtime> Debug for MockSleepRuntime<R>
sourceimpl<R: Runtime> SleepProvider for MockSleepRuntime<R>
impl<R: Runtime> SleepProvider for MockSleepRuntime<R>
type SleepFuture = Sleeping
type SleepFuture = Sleeping
A future returned by SleepProvider::sleep()
sourcefn sleep(&self, dur: Duration) -> Self::SleepFuture
fn sleep(&self, dur: Duration) -> Self::SleepFuture
Return a future that will be ready after duration
has
elapsed. Read more
sourcefn wallclock(&self) -> SystemTime
fn wallclock(&self) -> SystemTime
Return the SleepProvider’s view of the current wall-clock time. 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
sourceimpl<R: Runtime> Spawn for MockSleepRuntime<R>
impl<R: Runtime> Spawn for MockSleepRuntime<R>
sourceimpl<R: Runtime> TcpProvider for MockSleepRuntime<R>
impl<R: Runtime> TcpProvider for MockSleepRuntime<R>
type TcpStream = <R as TcpProvider>::TcpStream
type TcpStream = <R as TcpProvider>::TcpStream
The type for the TCP connections returned by Self::connect()
.
type TcpListener = <R as TcpProvider>::TcpListener
type TcpListener = <R as TcpProvider>::TcpListener
The type for the TCP listeners returned by Self::listen()
.
sourcefn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr
) -> Pin<Box<dyn Future<Output = IoResult<Self::TcpStream>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr
) -> Pin<Box<dyn Future<Output = IoResult<Self::TcpStream>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Launch a TCP connection to a given socket address. Read more
sourcefn listen<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr
) -> Pin<Box<dyn Future<Output = IoResult<Self::TcpListener>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn listen<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr
) -> Pin<Box<dyn Future<Output = IoResult<Self::TcpListener>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Open a TCP listener on a given socket address.
sourceimpl<R: Runtime> TlsProvider<<R as TcpProvider>::TcpStream> for MockSleepRuntime<R>
impl<R: Runtime> TlsProvider<<R as TcpProvider>::TcpStream> for MockSleepRuntime<R>
type Connector = <R as TlsProvider<<R as TcpProvider>::TcpStream>>::Connector
type Connector = <R as TlsProvider<<R as TcpProvider>::TcpStream>>::Connector
The Connector object that this provider can return.
type TlsStream = <R as TlsProvider<<R as TcpProvider>::TcpStream>>::TlsStream
type TlsStream = <R as TlsProvider<<R as TcpProvider>::TcpStream>>::TlsStream
The type of the stream returned by that connector.
sourcefn tls_connector(&self) -> Self::Connector
fn tls_connector(&self) -> Self::Connector
Return a TLS connector for use with this runtime.
sourceimpl<R: Runtime> UdpProvider for MockSleepRuntime<R>
impl<R: Runtime> UdpProvider for MockSleepRuntime<R>
type UdpSocket = <R as UdpProvider>::UdpSocket
type UdpSocket = <R as UdpProvider>::UdpSocket
The type of Udp Socket returned by Self::bind()
Auto Trait Implementations
impl<R> RefUnwindSafe for MockSleepRuntime<R> where
R: RefUnwindSafe,
impl<R> Send for MockSleepRuntime<R>
impl<R> Sync for MockSleepRuntime<R>
impl<R> Unpin for MockSleepRuntime<R> where
R: Unpin,
impl<R> UnwindSafe for MockSleepRuntime<R> where
R: UnwindSafe,
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
impl<Sp> SpawnExt for Sp where
Sp: Spawn + ?Sized,
impl<Sp> SpawnExt for Sp where
Sp: Spawn + ?Sized,
fn spawn<Fut>(&self, future: Fut) -> Result<(), SpawnError> where
Fut: 'static + Future<Output = ()> + Send,
fn spawn<Fut>(&self, future: Fut) -> Result<(), SpawnError> where
Fut: 'static + Future<Output = ()> + Send,
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: 'static + Future + Send,
<Fut as Future>::Output: Send,
fn spawn_with_handle<Fut>(
&self,
future: Fut
) -> Result<RemoteHandle<<Fut as Future>::Output>, SpawnError> where
Fut: 'static + Future + Send,
<Fut as Future>::Output: Send,
Spawns a task that polls the given future to completion and returns a future that resolves to the spawned future’s output. 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