pub struct TestLoopV2 {
pub data: TestLoopData,
pub current_time: Duration,
/* private fields */
}
Expand description
Main struct for the Test Loop framework.
The TestLoopData
should contain all the business logic state that is relevant
to the test. All possible Event
that are sent to the event loop are callbacks.
See TestLoopData for mode details.
Events are sent to the testloop, with a possible delay, via the pending_events_sender.
Fields§
§data: TestLoopData
The data that is stored and accessed by the test loop.
current_time: Duration
The current virtual time.
Implementations§
Source§impl TestLoopV2
impl TestLoopV2
pub fn new() -> Self
Sourcepub fn future_spawner(&self) -> TestLoopFututeSpawner
pub fn future_spawner(&self) -> TestLoopFututeSpawner
Returns a FutureSpawner that can be used to spawn futures into the loop.
Sourcepub fn async_computation_spawner(
&self,
artificial_delay: impl Fn(&str) -> Duration + Send + Sync + 'static,
) -> TestLoopAsyncComputationSpawner
pub fn async_computation_spawner( &self, artificial_delay: impl Fn(&str) -> Duration + Send + Sync + 'static, ) -> TestLoopAsyncComputationSpawner
Returns an AsyncComputationSpawner that can be used to spawn async computation into the
loop. The artificial_delay
allows the test to determine an artificial delay that the
computation should take, based on the name of the computation.
Sourcepub fn sender(&self) -> PendingEventsSender
pub fn sender(&self) -> PendingEventsSender
Returns a sender that can be used anywhere to send events to the loop.
Sourcepub fn send_adhoc_event(
&self,
description: String,
callback: impl FnOnce(&mut TestLoopData) + Send + 'static,
)
pub fn send_adhoc_event( &self, description: String, callback: impl FnOnce(&mut TestLoopData) + Send + 'static, )
Sends any ad-hoc event to the loop.
pub fn register_actor<A>(
&mut self,
actor: A,
adapter: Option<Arc<LateBoundSender<TestLoopSender<A>>>>,
) -> TestLoopSender<A>where
A: Actor + 'static,
pub fn register_actor_for_index<A>(
&mut self,
index: usize,
actor: A,
adapter: Option<Arc<LateBoundSender<TestLoopSender<A>>>>,
) -> TestLoopSender<A>where
A: Actor + 'static,
pub fn set_every_event_callback( &mut self, callback: impl FnMut(&TestLoopData) + 'static, )
Sourcepub fn run_for(&mut self, duration: Duration)
pub fn run_for(&mut self, duration: Duration)
Runs the test loop for the given duration. This function may be called multiple times, but further test handlers may not be registered after the first call.
Sourcepub fn run_until(
&mut self,
condition: impl Fn(&mut TestLoopData) -> bool,
maximum_duration: Duration,
)
pub fn run_until( &mut self, condition: impl Fn(&mut TestLoopData) -> bool, maximum_duration: Duration, )
Run until the given condition is true, asserting that it happens before the maximum duration is reached.
To maximize logical consistency, the condition is only checked before the clock would advance. If it returns true, execution stops before advancing the clock.
pub fn shutdown_and_drain_remaining_events(self, maximum_duration: Duration)
pub fn run_instant(&mut self)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TestLoopV2
impl !RefUnwindSafe for TestLoopV2
impl !Send for TestLoopV2
impl !Sync for TestLoopV2
impl Unpin for TestLoopV2
impl !UnwindSafe for TestLoopV2
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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<A, B> IntoMultiSender<B> for Awhere
B: MultiSenderFrom<A>,
impl<A, B> IntoMultiSender<B> for Awhere
B: MultiSenderFrom<A>,
fn as_multi_sender(self: &Arc<A>) -> B
fn into_multi_sender(self) -> B
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request