Struct near_async::test_loop::TestLoop
source · pub struct TestLoop<Data: 'static, Event: Debug + Send + 'static> {
pub data: Data,
/* private fields */
}Expand description
Main struct for the Test Loop framework.
The Data type should contain all the business logic state that is relevant
to the test. The Event type should contain all the possible events that
are sent to the event loop.
The convention is that, for single-instance tests,
Datashould be a struct with a derive_more::AsMut and derive_more::AsRef (so thatDataimplements AsMutand AsRef for each of its fields.) Eventshould be an enum with a derive(EnumTryInto, EnumFrom), so that it implements TryIntoand From for each of its variants. and that for multi-instance tests, DataisVec<SingleData>andEventis(usize, SingleEvent).
Fields§
§data: DataImplementations§
source§impl<Data: 'static, Event: Debug + Send + 'static> TestLoop<Data, Event>
impl<Data: 'static, Event: Debug + Send + 'static> TestLoop<Data, Event>
sourcepub fn register_delayed_action_handler<T>(&mut self)where
T: 'static,
Data: AsMut<T>,
Event: TryIntoOrSelf<TestLoopDelayedActionEvent<T>> + From<TestLoopDelayedActionEvent<T>> + 'static,
pub fn register_delayed_action_handler<T>(&mut self)where
T: 'static,
Data: AsMut<T>,
Event: TryIntoOrSelf<TestLoopDelayedActionEvent<T>> + From<TestLoopDelayedActionEvent<T>> + 'static,
Shorthand for registering this frequently used handler.
source§impl<Data: 'static, Event: Debug + Send + 'static> TestLoop<Vec<Data>, (usize, Event)>
impl<Data: 'static, Event: Debug + Send + 'static> TestLoop<Vec<Data>, (usize, Event)>
sourcepub fn register_delayed_action_handler_for_index<T>(&mut self, idx: usize)where
T: 'static,
Data: AsMut<T>,
Event: TryIntoOrSelf<TestLoopDelayedActionEvent<T>> + From<TestLoopDelayedActionEvent<T>> + 'static,
pub fn register_delayed_action_handler_for_index<T>(&mut self, idx: usize)where
T: 'static,
Data: AsMut<T>,
Event: TryIntoOrSelf<TestLoopDelayedActionEvent<T>> + From<TestLoopDelayedActionEvent<T>> + 'static,
Shorthand for registering this frequently used handler for a multi-instance test.
source§impl<Data, Event: Debug + Send + 'static> TestLoop<Data, Event>
impl<Data, Event: Debug + Send + 'static> TestLoop<Data, Event>
pub fn sender(&self) -> DelaySender<Event>
pub fn clock(&self) -> Clock
pub fn shutting_down(&self) -> Arc<AtomicBool>
sourcepub fn register_handler(&mut self, handler: LoopEventHandler<Data, Event>)
pub fn register_handler(&mut self, handler: LoopEventHandler<Data, Event>)
Registers a new event handler to the test loop.
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 Data) -> bool,
maximum_duration: Duration,
)
pub fn run_until( &mut self, condition: impl Fn(&mut Data) -> 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.
sourcepub fn shutdown_and_drain_remaining_events(self, maximum_duration: Duration)
pub fn shutdown_and_drain_remaining_events(self, maximum_duration: Duration)
Used to finish off remaining events that are still in the loop. This can be necessary if the destructor of some components wait for certain condition to become true. Otherwise, the destructors may end up waiting forever. This also helps avoid a panic when destructing TestLoop itself, as it asserts that all events have been handled.
pub fn run_instant(&mut self)
pub fn future_spawner(&self) -> TestLoopFutureSpawner
Trait Implementations§
Auto Trait Implementations§
impl<Data, Event> Freeze for TestLoop<Data, Event>where
Data: Freeze,
impl<Data, Event> !RefUnwindSafe for TestLoop<Data, Event>
impl<Data, Event> !Send for TestLoop<Data, Event>
impl<Data, Event> !Sync for TestLoop<Data, Event>
impl<Data, Event> Unpin for TestLoop<Data, Event>
impl<Data, Event> !UnwindSafe for TestLoop<Data, Event>
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