1

I am working on tests using the actix-lua crate:

#[should_panic]
#[test]
fn lua_actor_user_error() {
    let system = System::new("test");

    let lua_addr = lua_actor_with_handle(
        r#"
    print("before")
    error("foo")
    print("after")
    "#,
    )
    .start();

    let l = lua_addr.send(LuaMessage::from(0));
    let fut = async move {
        let res = l.await;
        match res {
            Ok(_res) => {
                // it should panic. 
                // and it does, but it seems the test does not pass
                // running 1 test
                // thread 'actor::tests::lua_actor_user_error' panicked at ... src/actor.rs:205:31
                System::current().stop();
            }
            Err(e) => {
                println!("actor dead {}", e);
            }
        };
    };
    Arbiter::spawn(fut);
    
    system.run();
}

I can see from the output that the panic occurs as expected:

running 1 test
before
thread 'actor::tests::lua_actor_user_error' panicked at 'RuntimeError("[string \"Prelude\"]:35: [string \"handle\"]:3: foo\nstack traceback:\n\t[C]: in ?\n\t[C]: in function \'error\'\n\t[string \"Prelude\"]:35: in function \'__run\'")', src/actor.rs:205:31

The code in question.

The test never completes. Am I missing something?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Njuguna Mureithi
  • 3,506
  • 1
  • 21
  • 41
  • The panic occurs inside the callback passed to the Arbiter. I'd guess the arbiter catches the panic, and returns that information when you `join()`, just as [`Thread`](https://doc.rust-lang.org/std/thread/fn.spawn.html) does in the stdlib: if a panic occurs inside an stdlib thread, it doesn't take down the process, the panic information is just stored and can be retrieved by `join()`. Only uncaught panics on the main thread will take down the process. – Masklinn Aug 01 '20 at 10:01

0 Answers0