tokio-rs / tokio

A runtime for writing reliable asynchronous applications with Rust. Provides I/O, networking, scheduling, timers, ...

Home Page:https://tokio.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow setting `unhandled_panic` behavior as option on `tokio::test`

xortive opened this issue · comments

commented

Is your feature request related to a problem? Please describe.
I have several unit tests that run some handler code that is under test in a tokio::spawned task, and sends/receives bytes to/from that handler code from the main task. My AsyncRead + AsyncWrite mock will panic if it sees unexpected bytes, and if this happens in the background task the test will hang. I'd prefer the test to shut down in this scenario, and so I'm using the unhandled_panic option introduced by #4516.

Describe the solution you'd like
#[tokio::test(unhandled_panic = ShutdownRuntime)

Describe alternatives you've considered
Currently I manually set up a tokio runtime for my tests that require this behavior.

I’m fine adding this feature.