Skip to content

Commit

Permalink
Panic on errors in test::block_on_actor
Browse files Browse the repository at this point in the history
Same as what we did for test::block_on_local_actor.
  • Loading branch information
Thomasdezeeuw committed Mar 21, 2024
1 parent 249ea78 commit cbfcfcc
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions rt/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,13 @@ where
/// This requires the `NewActor` (`NA`) to be [`Send`] as they are send to
/// another thread which runs the *test* runtime (and thus the actor). The actor
/// (`NA::Actor`) itself doesn't have to be `Send`.
pub fn block_on_actor<NA>(mut new_actor: NA, arg: NA::Argument) -> Result<(), BlockOnError<NA>>
pub fn block_on_actor<NA>(mut new_actor: NA, arg: NA::Argument)
where
NA: NewActor<RuntimeAccess = ThreadSafe> + Send + 'static,
NA::Actor: Send + std::marker::Sync + 'static,
<NA::Actor as Actor>::Error: Send,
<NA::Actor as Actor>::Error: fmt::Display + Send,
NA::Argument: Send,
NA::Error: Send,
NA::Error: fmt::Display + Send,
{
let (sender, mut receiver) = new_oneshot();
let waker = SyncWaker::new();
Expand All @@ -312,13 +312,17 @@ where
runtime_ref.spawn_future(future, FutureOptions::default());
Ok(())
});
waker
.block_on(receiver.recv_once())
.expect("failed to receive result from test runtime")
match waker.block_on(receiver.recv_once()) {
Some(Ok(())) => {}
Some(Err(BlockOnError::<NA>::Creating(err))) => panic!("failed to create actor: {err}"),
Some(Err(BlockOnError::<NA>::Running(err))) => panic!("actor hit an error: {err}"),
Some(Err(BlockOnError::<NA>::Panic(panic))) => resume_unwind(panic),
None => panic!("failed to wait on actor"),
}
}

/// Error return by spawn an actor and waiting for the result.
pub enum BlockOnError<NA: NewActor> {
enum BlockOnError<NA: NewActor> {
/// Error creating the actor.
Creating(NA::Error),
/// Error running the actor.
Expand Down

0 comments on commit cbfcfcc

Please sign in to comment.