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> Blocking for MockSleepRuntime<R>
impl<R: Runtime> Blocking for MockSleepRuntime<R>
Source§type ThreadHandle<T: Send + 'static> = <R as Blocking>::ThreadHandle<T>
type ThreadHandle<T: Send + 'static> = <R as Blocking>::ThreadHandle<T>
spawn_blocking Read moreSource§fn spawn_blocking<F, T>(&self, f: F) -> <R as Blocking>::ThreadHandle<T>
fn spawn_blocking<F, T>(&self, f: F) -> <R as Blocking>::ThreadHandle<T>
Source§fn reenter_block_on<F>(&self, future: F) -> F::Output
fn reenter_block_on<F>(&self, future: F) -> F::Output
Blocking::spawn_blocking Read moreSource§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> CoarseTimeProvider for MockSleepRuntime<R>
impl<R: Runtime> CoarseTimeProvider for MockSleepRuntime<R>
Source§fn now_coarse(&self) -> CoarseInstant
fn now_coarse(&self) -> CoarseInstant
CoarseTimeProvider’s view of the current instant. Read moreSource§impl<R: Runtime> NetStreamProvider<SocketAddr> for MockSleepRuntime<R>
impl<R: Runtime> NetStreamProvider<SocketAddr> for MockSleepRuntime<R>
Source§type Stream = FakeStream
type Stream = FakeStream
Self::connect().Source§type Listener = FakeListener<SocketAddr>
type Listener = FakeListener<SocketAddr>
Self::listen().Source§fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
_addr: &'life1 SocketAddr,
) -> Pin<Box<dyn Future<Output = IoResult<Self::Stream>> + 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::Stream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§impl<R: Runtime> NetStreamProvider for MockSleepRuntime<R>
impl<R: Runtime> NetStreamProvider for MockSleepRuntime<R>
Source§type Stream = <R as NetStreamProvider>::Stream
type Stream = <R as NetStreamProvider>::Stream
Self::connect().Source§type Listener = <R as NetStreamProvider>::Listener
type Listener = <R as NetStreamProvider>::Listener
Self::listen().Source§fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr,
) -> Pin<Box<dyn Future<Output = IoResult<Self::Stream>> + 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::Stream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§impl<R: Runtime> SleepProvider for MockSleepRuntime<R>
impl<R: Runtime> SleepProvider for MockSleepRuntime<R>
Source§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> TlsProvider<<R as NetStreamProvider>::Stream> for MockSleepRuntime<R>
impl<R: Runtime> TlsProvider<<R as NetStreamProvider>::Stream> for MockSleepRuntime<R>
Source§type Connector = <R as TlsProvider<<R as NetStreamProvider>::Stream>>::Connector
type Connector = <R as TlsProvider<<R as NetStreamProvider>::Stream>>::Connector
Source§type TlsStream = <R as TlsProvider<<R as NetStreamProvider>::Stream>>::TlsStream
type TlsStream = <R as TlsProvider<<R as NetStreamProvider>::Stream>>::TlsStream
Source§fn tls_connector(&self) -> Self::Connector
fn tls_connector(&self) -> Self::Connector
Source§fn supports_keying_material_export(&self) -> bool
fn supports_keying_material_export(&self) -> bool
Source§impl<R> ToplevelBlockOn for MockSleepRuntime<R>where
R: ToplevelBlockOn + Runtime,
impl<R> ToplevelBlockOn for MockSleepRuntime<R>where
R: ToplevelBlockOn + Runtime,
Source§impl<R: Runtime> UdpProvider for MockSleepRuntime<R>
impl<R: Runtime> UdpProvider for MockSleepRuntime<R>
Source§type UdpSocket = <R as UdpProvider>::UdpSocket
type UdpSocket = <R as UdpProvider>::UdpSocket
Self::bind()Auto Trait Implementations§
impl<R> Freeze for MockSleepRuntime<R>where
R: Freeze,
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> NetStreamProvider<SocketAddr> for T
impl<T> NetStreamProvider<SocketAddr> for T
Source§type Stream = Stream
type Stream = Stream
Self::connect().Source§type Listener = Listener
type Listener = Listener
Self::listen().Source§fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr,
) -> Pin<Box<dyn Future<Output = Result<Stream, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
T: 'async_trait,
fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr,
) -> Pin<Box<dyn Future<Output = Result<Stream, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
T: 'async_trait,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R> RuntimeSubstExt for Rwhere
R: Runtime,
impl<R> RuntimeSubstExt for Rwhere
R: Runtime,
Source§fn with_tcp_provider<T>(
&self,
new_tcp: T,
) -> CompoundRuntime<R, R, R, T, R, R, R>
fn with_tcp_provider<T>( &self, new_tcp: T, ) -> CompoundRuntime<R, R, R, T, R, R, R>
Source§fn with_sleep_provider<T>(
&self,
new_sleep: T,
) -> CompoundRuntime<R, T, R, R, R, R, R>
fn with_sleep_provider<T>( &self, new_sleep: T, ) -> CompoundRuntime<R, T, R, R, R, R, R>
Source§fn with_coarse_time_provider<T>(
&self,
new_coarse_time: T,
) -> CompoundRuntime<R, R, T, R, R, R, R>
fn with_coarse_time_provider<T>( &self, new_coarse_time: T, ) -> CompoundRuntime<R, R, T, R, R, R, R>
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 moreSource§impl<Sp> SpawnExt for Sp
impl<Sp> SpawnExt for Sp
Source§fn spawn<Fut>(&self, future: Fut) -> Result<(), SpawnError>
fn spawn<Fut>(&self, future: Fut) -> Result<(), SpawnError>
() to
completion. Read moreSource§fn spawn_with_handle<Fut>(
&self,
future: Fut,
) -> Result<RemoteHandle<<Fut as Future>::Output>, SpawnError>
fn spawn_with_handle<Fut>( &self, future: Fut, ) -> Result<RemoteHandle<<Fut as Future>::Output>, SpawnError>
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T> Runtime for Twhere
T: Sync + Send + Spawn + Blocking + Clone + SleepProvider + CoarseTimeProvider + NetStreamProvider + NetStreamProvider<SocketAddr> + TlsProvider<<T as NetStreamProvider>::Stream> + UdpProvider + Debug + 'static,
impl<T> ToplevelRuntime for Twhere
T: Runtime + ToplevelBlockOn,
Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.