Struct tor_rtmock::MockSleepRuntime
source · pub struct MockSleepRuntime<R: Runtime> { /* private fields */ }Expand description
A deprecated wrapper Runtime that overrides SleepProvider for the underlying runtime.
§Deprecated
The MockSleepProvider used here has some limitations.
See its documentation for more information.
Use MockRuntime for new tests.
Implementations§
source§impl<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!
NOTE Instead of using this, consider MockRuntime,
which will fully isolate the test case
(albeit at the cost of demanding manual management of the simulated time).
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§
source§impl<R: Runtime> BlockOn for MockSleepRuntime<R>
impl<R: Runtime> BlockOn for MockSleepRuntime<R>
source§impl<R: Clone + Runtime> Clone for MockSleepRuntime<R>
impl<R: Clone + Runtime> Clone for MockSleepRuntime<R>
source§fn clone(&self) -> MockSleepRuntime<R>
fn clone(&self) -> MockSleepRuntime<R>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<R: Runtime> SleepProvider for MockSleepRuntime<R>
impl<R: Runtime> SleepProvider for MockSleepRuntime<R>
§type SleepFuture = <MockSleepProvider as SleepProvider>::SleepFuture
type SleepFuture = <MockSleepProvider as SleepProvider>::SleepFuture
SleepProvider::sleep()source§fn sleep(&self, dur: Duration) -> Self::SleepFuture
fn sleep(&self, dur: Duration) -> Self::SleepFuture
duration has
elapsed.source§fn wallclock(&self) -> SystemTime
fn wallclock(&self) -> SystemTime
source§fn block_advance<T: Into<String>>(&self, reason: T)
fn block_advance<T: Into<String>>(&self, reason: T)
source§fn release_advance<T: Into<String>>(&self, reason: T)
fn release_advance<T: Into<String>>(&self, reason: T)
block_advance no
longer exists, and it’s fine to move time forward if nothing else is blocking advances. Read moresource§fn allow_one_advance(&self, dur: Duration)
fn allow_one_advance(&self, dur: Duration)
block_advance API has been used. Read moresource§impl<R: Runtime> Spawn for MockSleepRuntime<R>
impl<R: Runtime> Spawn for MockSleepRuntime<R>
source§impl<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
Self::connect().§type TcpListener = <R as TcpProvider>::TcpListener
type TcpListener = <R as TcpProvider>::TcpListener
Self::listen().source§fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr
) -> Pin<Box<dyn Future<Output = IoResult<Self::TcpStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: '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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
source§fn listen<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr
) -> Pin<Box<dyn Future<Output = IoResult<Self::TcpListener>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: '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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
source§impl<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
§type TlsStream = <R as TlsProvider<<R as TcpProvider>::TcpStream>>::TlsStream
type TlsStream = <R as TlsProvider<<R as TcpProvider>::TcpStream>>::TlsStream
source§fn tls_connector(&self) -> Self::Connector
fn tls_connector(&self) -> Self::Connector
source§impl<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
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§
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>
source§impl<T> SleepProviderExt for Twhere
T: SleepProvider,
impl<T> SleepProviderExt for Twhere
T: SleepProvider,
source§fn 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,
source§fn sleep_until_wallclock(
&self,
when: SystemTime
) -> SleepUntilWallclock<'_, Self>
fn sleep_until_wallclock( &self, when: SystemTime ) -> SleepUntilWallclock<'_, Self>
when or later, trying to
recover from clock jumps. Read more§impl<Sp> SpawnExt for Spwhere
Sp: Spawn + ?Sized,
impl<Sp> SpawnExt for Spwhere
Sp: Spawn + ?Sized,
§fn spawn<Fut>(&self, future: Fut) -> Result<(), SpawnError>
fn spawn<Fut>(&self, future: Fut) -> Result<(), SpawnError>
alloc only.() to
completion. Read more