pub struct SimReceiver<T: Serialize + DeserializeOwned, O: Ordering, R: Retries>(/* private fields */);sim only.Expand description
A receiver for an external bincode stream in a simulation.
Implementations§
Source§impl<T: Serialize + DeserializeOwned, O: Ordering, R: Retries> SimReceiver<T, O, R>
impl<T: Serialize + DeserializeOwned, O: Ordering, R: Retries> SimReceiver<T, O, R>
Sourcepub fn assert_no_more(self) -> impl Future<Output = ()>where
T: Debug,
pub fn assert_no_more(self) -> impl Future<Output = ()>where
T: Debug,
Asserts that the stream has ended and no more messages can possibly arrive.
If the check cannot be answered without running pending nondeterministic work (such as ticks with buffered inputs):
- Under
CompiledSim::exhaustive, the search forks: one instance performs the check and ends there, while sibling instances skip the check and continue. - In other modes, the pending work runs; afterwards, sending more input and then attempting to receive output will panic.
Source§impl<T: Serialize + DeserializeOwned> SimReceiver<T, TotalOrder, ExactlyOnce>
impl<T: Serialize + DeserializeOwned> SimReceiver<T, TotalOrder, ExactlyOnce>
Sourcepub fn next(&self) -> impl use<'_, T> + Future<Output = T>
pub fn next(&self) -> impl use<'_, T> + Future<Output = T>
Receives the next message from the external bincode stream, waiting (and letting the scheduler run any pending simulation work) until one is available. If the simulation becomes quiescent without producing a message, the test fails.
This is safe to use in the middle of a test; to observe the absence of a message,
use Self::try_next or Self::assert_no_more.
Sourcepub async fn try_next(&self) -> Option<T>
pub async fn try_next(&self) -> Option<T>
Receives the next message from the external bincode stream, or returns None if no
more messages can possibly arrive.
If answering requires forcing pending nondeterministic work to run, then afterwards,
sending more input and then attempting to receive output will panic. Prefer
Self::next (or Self::assert_no_more) when possible.
Sourcepub fn collect_n<C: Default + Extend<T>>(
&self,
n: usize,
) -> impl use<'_, T, C> + Future<Output = C>
pub fn collect_n<C: Default + Extend<T>>( &self, n: usize, ) -> impl use<'_, T, C> + Future<Output = C>
Receives the next n messages from the external bincode stream, waiting (and letting
the scheduler run any pending simulation work) until they are available. If the
simulation becomes quiescent before n messages arrive, the test fails.
Like Self::next, this is safe to use in the middle of a test. It does not check
that the stream ends afterwards; use Self::collect_n_only for that.
Sourcepub async fn collect_n_only<C: Default + Extend<T>>(self, n: usize) -> Cwhere
T: Debug,
pub async fn collect_n_only<C: Default + Extend<T>>(self, n: usize) -> Cwhere
T: Debug,
Receives the next n messages (like Self::collect_n) and then asserts that the
stream ends (like Self::assert_no_more, forking the search in exhaustive mode).
Sourcepub async fn collect<C: Default + Extend<T>>(self) -> C
pub async fn collect<C: Default + Extend<T>>(self) -> C
Collects all remaining messages from the external bincode stream into a collection, waiting until no more messages can possibly arrive.
If this has to force pending nondeterministic work to run, it should be the last
observation of the test: afterwards, sending more input and then attempting to
receive output will panic. When the number of expected messages is known, prefer
Self::collect_n / Self::collect_n_only.
Sourcepub fn assert_yields<T2: Debug, I: IntoIterator<Item = T2>>(
&self,
expected: I,
) -> impl use<'_, T, T2, I> + Future<Output = ()>
pub fn assert_yields<T2: Debug, I: IntoIterator<Item = T2>>( &self, expected: I, ) -> impl use<'_, T, T2, I> + Future<Output = ()>
Asserts that the stream yields exactly the expected sequence of messages, in order.
This does not check that the stream ends, use Self::assert_yields_only for that.
Like Self::next, this is safe to use in the middle of a test.
Sourcepub fn assert_yields_only<T2: Debug, I: IntoIterator<Item = T2>>(
&self,
expected: I,
) -> impl use<'_, T, T2, I> + Future<Output = ()>
pub fn assert_yields_only<T2: Debug, I: IntoIterator<Item = T2>>( &self, expected: I, ) -> impl use<'_, T, T2, I> + Future<Output = ()>
Asserts that the stream yields only the expected sequence of messages, in order,
and then ends (like Self::assert_no_more, forking the search in exhaustive mode).
Source§impl<T: Serialize + DeserializeOwned> SimReceiver<T, NoOrder, ExactlyOnce>
impl<T: Serialize + DeserializeOwned> SimReceiver<T, NoOrder, ExactlyOnce>
Sourcepub fn collect_n_sorted<C: Default + Extend<T> + AsMut<[T]>>(
&self,
n: usize,
) -> impl use<'_, T, C> + Future<Output = C>where
T: Ord,
pub fn collect_n_sorted<C: Default + Extend<T> + AsMut<[T]>>(
&self,
n: usize,
) -> impl use<'_, T, C> + Future<Output = C>where
T: Ord,
Receives the next n messages, sorted, waiting (and letting the scheduler run any
pending simulation work) until they are available. If the simulation becomes quiescent
before n messages arrive, the test fails.
Like SimReceiver::next, this is safe to use in the middle of a test.
Sourcepub async fn collect_sorted<C: Default + Extend<T> + AsMut<[T]>>(self) -> Cwhere
T: Ord,
pub async fn collect_sorted<C: Default + Extend<T> + AsMut<[T]>>(self) -> Cwhere
T: Ord,
Collects all remaining messages from the external bincode stream into a collection, sorting them. This will wait until no more messages can possibly arrive.
If this has to force pending nondeterministic work to run, it should be the last
observation of the test; see collect.
Sourcepub fn assert_yields_unordered<T2: Debug, I: IntoIterator<Item = T2>>(
&self,
expected: I,
) -> impl use<'_, T, T2, I> + Future<Output = ()>
pub fn assert_yields_unordered<T2: Debug, I: IntoIterator<Item = T2>>( &self, expected: I, ) -> impl use<'_, T, T2, I> + Future<Output = ()>
Asserts that the stream yields exactly the expected sequence of messages, in some order.
This does not check that the stream ends, use Self::assert_yields_only_unordered for that.
Like SimReceiver::next, this is safe to use in the middle of a test.
Sourcepub fn assert_yields_only_unordered<T2: Debug, I: IntoIterator<Item = T2>>(
&self,
expected: I,
) -> impl use<'_, T, T2, I> + Future<Output = ()>
pub fn assert_yields_only_unordered<T2: Debug, I: IntoIterator<Item = T2>>( &self, expected: I, ) -> impl use<'_, T, T2, I> + Future<Output = ()>
Asserts that the stream yields only the expected sequence of messages, in some order,
and then ends (like Self::assert_no_more, forking the search in exhaustive mode).
Trait Implementations§
Source§impl<T: Serialize + DeserializeOwned, O: Ordering, R: Retries> Clone for SimReceiver<T, O, R>
impl<T: Serialize + DeserializeOwned, O: Ordering, R: Retries> Clone for SimReceiver<T, O, R>
impl<T: Serialize + DeserializeOwned, O: Ordering, R: Retries> Copy for SimReceiver<T, O, R>
Auto Trait Implementations§
impl<T, O, R> Freeze for SimReceiver<T, O, R>
impl<T, O, R> RefUnwindSafe for SimReceiver<T, O, R>
impl<T, O, R> Send for SimReceiver<T, O, R>
impl<T, O, R> Sync for SimReceiver<T, O, R>
impl<T, O, R> Unpin for SimReceiver<T, O, R>
impl<T, O, R> UnsafeUnpin for SimReceiver<T, O, R>
impl<T, O, R> UnwindSafe for SimReceiver<T, O, R>
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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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 more