-
Notifications
You must be signed in to change notification settings - Fork 29
Testing of asynchronous code #38
Comments
The Tokio current_thread::Runtime spawns no threads. |
This is not an issue anymore, as long as the top-level executor call returns these panics-as-errors to you, your test function can now return the error to signal a failure. |
Not related to Tokio, but creating a Future's |
In case there are subscribers to this that haven't seen it, quite a while back a |
Right now, rust's standard way of writing tests and the standard way of executing futures (tokio) are at odds with eachother. The test framework expects a panic on test failure - tokio catches panics and treats them as normal errors. The test framework tries to run multiple tests in parallel where it can - tokio immediately spawns one thread per CPU core when you run it. This makes testing asynchronous code pretty hard, and that's something we should fix.
I think to fix this, we need a simpler futures executor that doesn't include quite so many batteries. Instead, a
run
function that just runs like a regular function - without trying to do anything with threads or panic catching. Ideally, in the name of keeping test and prod environments similar, I would suggest we at least consider making tokio that simpler executor*. Also possible would be taking something like toykio further, or potentially even going the full way to supporting#[test] async fn ...
in future.*and separating all of the threading magic done by tokio out into a wrapper around a simpler core executor. This would be a big move, and I may be missing a whole bunch of reasons why its a bad idea, but on the bright side the extra flexibility could help people who
The text was updated successfully, but these errors were encountered: