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,

  • Data should be a struct with a derive_more::AsMut and derive_more::AsRef (so that Data implements AsMut and AsRef for each of its fields.)
  • Event should be an enum with a derive(EnumTryInto, EnumFrom), so that it implements TryInto and From for each of its variants. and that for multi-instance tests, Data is Vec<SingleData> and Event is (usize, SingleEvent).

Fields§

§data: Data

Implementations§

source§

impl<Data: 'static, Event: Debug + Send + 'static> TestLoop<Data, Event>

source

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)>

source

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>

source

pub fn sender(&self) -> DelaySender<Event>

source

pub fn clock(&self) -> Clock

source

pub fn shutting_down(&self) -> Arc<AtomicBool>

source

pub fn register_handler(&mut self, handler: LoopEventHandler<Data, Event>)

Registers a new event handler to the test loop.

source

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.

source

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.

source

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.

source

pub fn run_instant(&mut self)

source

pub fn future_spawner(&self) -> TestLoopFutureSpawner
where Event: From<Arc<TestLoopTask>>,

Trait Implementations§

source§

impl<Data: 'static, Event: Debug + Send + 'static> Drop for TestLoop<Data, Event>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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>
where Data: Unpin, Event: Unpin,

§

impl<Data, Event> !UnwindSafe for TestLoop<Data, Event>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FutureExt for T

source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<A, B> IntoMultiSender<B> for A
where B: MultiSenderFrom<A>,

source§

fn as_multi_sender(self: &Arc<A>) -> B

source§

fn into_multi_sender(self) -> B

source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<R, T> TryIntoOrSelf<R> for T
where T: TryInto<R, Error = T>,

source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more