Propagation panic in tokio thread to main test thread

Hello,

I'm using Tokio to test a client library and I ran into the below issue: an assert!() failed in a future chain though it was not captured by the main thread as a test failure.
I understand that I have to propagate the panic somehow but I couldn't find how.

Is there another (better) way to test async code that launching 1 runtime per test?

Thanks

 Running target/debug/deps/valid_login-aead7c7968a6629c

running 1 test
2018-10-09 17:45:36 INFO  [swgoh_help::request::player_request] Response body = {"code":400,"error":"No allycode(s) specified","requestId":2235615109}
2018-10-09 17:45:36 WARN  [swgoh_help::request::player_request] Error received from the server
thread 'tokio-runtime-worker-0' panicked at 'assertion failed: `(left == right)`
  left: `400`,
 right: `401`', tests/valid_login.rs:45:17
note: Run with `RUST_BACKTRACE=1` for a backtrace.
test valid_login ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
1 Like

You probably want to use block_on to run the future instead.

I would recommend using the current_thread runtime for tests, then run your "main" future with block_on

Worth a test indeed, thanks for the idea. I didn’t use it because I thought that we shouldn’t use that as it would block the main thread and prevent other I/O operations to complete

Works great, thanks a lot @carllerche

Actually, let me edit that. It does work but we loose the feature to run multiple tests in parallel.

So when I add more tests, if say the first one fails, none of the remaining tests will be run.

Any idea how to fix that?

Solutions regarding handling of non-main thread panics is something I'm interested in as well. This seems to be a general issue rather than specific to tokio?

When I learned that non-main Rust threads will let other threads, including the main thread, continue on panics, I was very surprised. Do any of you know the details of the reasoning behind this decision? Link to related issues or blog posts would be greatly appreciated.

Right now I'm leaning towards using abort on panic just to make sure I notice dead (non-main) threads:
https://rust-lang-nursery.github.io/edition-guide/rust-2018/error-handling-and-panics/aborting-on-panic.html

What are your thoughts on this? Sorry if I'm off-topic since you were discussing panics in the context of tokio and not the general case.