pub struct MockMonitor<T> { /* private fields */ }Expand description
Monitor implementation for deterministic tests.
MockMonitor protects a state value like the real monitor implementations,
but timeout methods use manually controlled mock elapsed time. Advancing the
mock time wakes waiters so they can recheck predicates and timeout budgets.
Implementations§
Source§impl<T> MockMonitor<T>
impl<T> MockMonitor<T>
Sourcepub fn set_elapsed(&self, elapsed: Duration)
pub fn set_elapsed(&self, elapsed: Duration)
Sets the current mock elapsed time.
This wakes timeout waiters so they can recheck their budgets.
§Arguments
elapsed- New mock elapsed time.
Sourcepub fn advance(&self, duration: Duration)
pub fn advance(&self, duration: Duration)
Advances mock elapsed time by a relative duration.
§Arguments
duration- Duration added to the current mock elapsed time.
Sourcepub fn reset_elapsed(&self)
pub fn reset_elapsed(&self)
Resets mock elapsed time to zero.
Sourcepub fn write_notify_one<R, F>(&self, f: F) -> R
pub fn write_notify_one<R, F>(&self, f: F) -> R
Sourcepub fn write_notify_all<R, F>(&self, f: F) -> R
pub fn write_notify_all<R, F>(&self, f: F) -> R
Sourcepub fn notify_one(&self)
pub fn notify_one(&self)
Wakes one waiter if one is blocked.
Sourcepub fn notify_all(&self)
pub fn notify_all(&self)
Wakes all waiters.
Trait Implementations§
Source§impl<T> AsRef<MockMonitor<T>> for ArcMockMonitor<T>
impl<T> AsRef<MockMonitor<T>> for ArcMockMonitor<T>
Source§fn as_ref(&self) -> &MockMonitor<T>
fn as_ref(&self) -> &MockMonitor<T>
Returns a reference to the wrapped mock monitor.
Source§impl<T: Send> AsyncConditionWaiter for MockMonitor<T>
Available on crate feature async only.
impl<T: Send> AsyncConditionWaiter for MockMonitor<T>
async only.Source§fn async_wait_until<'a, R, P, F>(
&'a self,
predicate: P,
action: F,
) -> AsyncMonitorFuture<'a, R>
fn async_wait_until<'a, R, P, F>( &'a self, predicate: P, action: F, ) -> AsyncMonitorFuture<'a, R>
Returns a future that waits until the predicate becomes true.
Source§fn async_wait_while<'a, R, P, F>(
&'a self,
predicate: P,
action: F,
) -> AsyncMonitorFuture<'a, R>
fn async_wait_while<'a, R, P, F>( &'a self, predicate: P, action: F, ) -> AsyncMonitorFuture<'a, R>
Returns a future that waits while the predicate remains true.
Source§impl<T: Send> AsyncNotificationWaiter for MockMonitor<T>
Available on crate feature async only.
impl<T: Send> AsyncNotificationWaiter for MockMonitor<T>
async only.Source§fn async_wait<'a>(&'a self) -> AsyncMonitorFuture<'a, ()>
fn async_wait<'a>(&'a self) -> AsyncMonitorFuture<'a, ()>
Returns a future that resolves after an async notification.
Source§impl<T: Send> AsyncTimeoutConditionWaiter for MockMonitor<T>
Available on crate feature async only.
impl<T: Send> AsyncTimeoutConditionWaiter for MockMonitor<T>
async only.Source§fn async_wait_until_for<'a, R, P, F>(
&'a self,
timeout: Duration,
predicate: P,
action: F,
) -> AsyncMonitorFuture<'a, WaitTimeoutResult<R>>
fn async_wait_until_for<'a, R, P, F>( &'a self, timeout: Duration, predicate: P, action: F, ) -> AsyncMonitorFuture<'a, WaitTimeoutResult<R>>
Returns a future that waits until the predicate becomes true or times out.
Source§fn async_wait_while_for<'a, R, P, F>(
&'a self,
timeout: Duration,
predicate: P,
action: F,
) -> AsyncMonitorFuture<'a, WaitTimeoutResult<R>>
fn async_wait_while_for<'a, R, P, F>( &'a self, timeout: Duration, predicate: P, action: F, ) -> AsyncMonitorFuture<'a, WaitTimeoutResult<R>>
Returns a future that waits while the predicate remains true or times out.
Source§impl<T: Send> AsyncTimeoutNotificationWaiter for MockMonitor<T>
Available on crate feature async only.
impl<T: Send> AsyncTimeoutNotificationWaiter for MockMonitor<T>
async only.Source§fn async_wait_for<'a>(
&'a self,
timeout: Duration,
) -> AsyncMonitorFuture<'a, WaitTimeoutStatus>
fn async_wait_for<'a>( &'a self, timeout: Duration, ) -> AsyncMonitorFuture<'a, WaitTimeoutStatus>
Returns a future that resolves after notification or mock timeout.
Source§impl<T> ConditionWaiter for MockMonitor<T>
impl<T> ConditionWaiter for MockMonitor<T>
Source§fn wait_until<R, P, F>(&self, predicate: P, action: F) -> R
fn wait_until<R, P, F>(&self, predicate: P, action: F) -> R
Blocks until the predicate becomes true, then runs the action.
Source§fn wait_while<R, P, F>(&self, predicate: P, action: F) -> R
fn wait_while<R, P, F>(&self, predicate: P, action: F) -> R
Blocks while the predicate remains true, then runs the action.
Source§impl<T: Default> Default for MockMonitor<T>
impl<T: Default> Default for MockMonitor<T>
Source§impl<T> From<T> for MockMonitor<T>
impl<T> From<T> for MockMonitor<T>
Source§impl<T> NotificationWaiter for MockMonitor<T>
impl<T> NotificationWaiter for MockMonitor<T>
Source§impl<T> Notifier for MockMonitor<T>
impl<T> Notifier for MockMonitor<T>
Source§fn notify_one(&self)
fn notify_one(&self)
Wakes one waiter if one is blocked.
Source§fn notify_all(&self)
fn notify_all(&self)
Wakes all waiters.
Source§impl<T> TimeoutConditionWaiter for MockMonitor<T>
impl<T> TimeoutConditionWaiter for MockMonitor<T>
Source§fn wait_until_for<R, P, F>(
&self,
timeout: Duration,
predicate: P,
action: F,
) -> WaitTimeoutResult<R>
fn wait_until_for<R, P, F>( &self, timeout: Duration, predicate: P, action: F, ) -> WaitTimeoutResult<R>
Blocks until the predicate becomes true or mock elapsed time reaches timeout.
Source§fn wait_while_for<R, P, F>(
&self,
timeout: Duration,
predicate: P,
action: F,
) -> WaitTimeoutResult<R>
fn wait_while_for<R, P, F>( &self, timeout: Duration, predicate: P, action: F, ) -> WaitTimeoutResult<R>
Blocks while the predicate remains true or until mock elapsed time reaches timeout.
Source§impl<T> TimeoutNotificationWaiter for MockMonitor<T>
impl<T> TimeoutNotificationWaiter for MockMonitor<T>
Source§fn wait_for(&self, timeout: Duration) -> WaitTimeoutStatus
fn wait_for(&self, timeout: Duration) -> WaitTimeoutStatus
Blocks until a notification happens or mock elapsed time reaches timeout.