Propagation panic in tokio thread to main test thread


#1

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

#2

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


#3

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


#4

Works great, thanks a lot @carllerche


#5

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?