-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bad error message when using IO resource after destroying runtime #6066
Comments
This is because each test creates a separate runtime, but they share an IO resource via a global. When the test that initialized the global exits, the other tests will fail because the IO resource stops working. |
Can you run the test with |
Sure, here it is.
|
Version
tokio v1.33.0
Platform
Windows 10 64-bits version 22H2
Description
Testing two
async fn
with#[tokio::test]
I got tests failed from because of tokio itself instead of one of my conditions. (This part https://github.com/tokio-rs/tokio/blob/tokio-1.33.0/tokio/src/runtime/io/scheduled_io.rs#L214)The error message is pretty bad and doesn't say what went wrong. Also the tests can complete or fail without any change between each call to cargo test.
The code is somewhat large to be put in a issue but I have it here --> https://github.com/PatatasDelPapa/sqlx_test/blob/b477db267cdcded3f5b268f518129c1f4aff2eb1/src/main.rs is just a single
main.rs
The resume is that I have a static
tokio::sync::OnceCell<sqlx::postgres::Pool<sqlx::Postgres>>
that I use in each test to get a connection to the Database. It seems that the connection when it's first created is tied to the runtime that created it and because each test have different runtime it causes troubles and tokio panics (possible explanation from the discord).I expected to see this happen:
Tests complete without issue
Or a good error message telling me why the test fails.
Instead, this happened:
Tests fails randomly
The error message doesn't give any indication of what went wrong.
The text was updated successfully, but these errors were encountered: