Struct tor_rtmock::MockSleepRuntime [−][src]
pub struct MockSleepRuntime<R: Runtime> { /* fields omitted */ }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 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
type SleepFuture = Sleeping
type SleepFuture = Sleeping
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 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
The type for the TCP connections returned by Self::connect().
type TcpListener = R::TcpListener
type TcpListener = R::TcpListener
The type for the TCP listeners returned by Self::listen().
Launch a TCP connection to a given socket address. Read more
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,
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.
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
Mutably borrows from an owned value. Read more
Pause until the wall-clock is at when or later, trying to
recover from clock jumps. Read more