pub struct TestHarness<A: Actor> { /* private fields */ }Expand description
Test harness for synchronous actor testing.
This harness allows testing actors without spawning tasks:
- Messages are queued in a local VecDeque
- Processing is explicit via
process_one()orprocess_all() - State is directly accessible for assertions
Implementations§
Source§impl<A: Actor> TestHarness<A>
impl<A: Actor> TestHarness<A>
Sourcepub fn with_state(actor: A, state: A::State) -> Self
pub fn with_state(actor: A, state: A::State) -> Self
Create a new test harness with a pre-initialized state.
This is useful when you want to test specific state transitions without going through the init process.
Sourcepub fn send(&mut self, msg: A::Message)
pub fn send(&mut self, msg: A::Message)
Send a message to the actor’s mailbox.
The message will be queued and processed when process_one()
or process_all() is called.
Sourcepub fn process_one(&mut self) -> Option<Directive>
pub fn process_one(&mut self) -> Option<Directive>
Process a single message from the mailbox.
Returns Some(flow) if a message was processed,
or None if the mailbox was empty.
Sourcepub fn process_all(&mut self) -> Vec<Directive>
pub fn process_all(&mut self) -> Vec<Directive>
Process all messages in the mailbox.
Returns a Vec of all Directive values returned by handle().
Processing stops early if any handler returns Directive::Stop.
Sourcepub fn process_until<F>(&mut self, condition: F) -> Vec<Directive>
pub fn process_until<F>(&mut self, condition: F) -> Vec<Directive>
Process messages until the mailbox is empty or a condition is met.
Returns the flows from all processed messages.
Sourcepub fn idle(&mut self) -> Directive
pub fn idle(&mut self) -> Directive
Call the actor’s idle hook.
This is useful for testing background work behavior.
Sourcepub fn mailbox_len(&self) -> usize
pub fn mailbox_len(&self) -> usize
Get the number of messages in the mailbox.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Check if cancelled.
Auto Trait Implementations§
impl<A> Freeze for TestHarness<A>
impl<A> RefUnwindSafe for TestHarness<A>
impl<A> Send for TestHarness<A>
impl<A> Sync for TestHarness<A>
impl<A> Unpin for TestHarness<A>
impl<A> UnsafeUnpin for TestHarness<A>
impl<A> UnwindSafe for TestHarness<A>
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> 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<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