Skip to content
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

Detached tasks in tests #2699

Closed
Darksonn opened this issue Jul 25, 2020 · 12 comments
Closed

Detached tasks in tests #2699

Darksonn opened this issue Jul 25, 2020 · 12 comments
Labels
A-tokio Area: The main tokio crate A-tokio-test Area: The tokio-test crate C-musing Category: musings about a better world M-runtime Module: tokio/runtime

Comments

@Darksonn
Copy link
Contributor

What should we do about detached tasks in tests? Can we help people out by detecting silent mistakes?

@Darksonn Darksonn added A-tokio-test Area: The tokio-test crate A-tokio Area: The main tokio crate M-runtime Module: tokio/runtime C-musing Category: musings about a better world labels Jul 25, 2020
@TheButlah
Copy link

This caught me off guard today - my code is using task::spawn without joining on the result because I don't want to block until the task finishes. But it meant that a bunch of panicking tasks were getting through CI without anyone noticing

@kstrafe
Copy link

kstrafe commented Dec 3, 2020

Can we remove the catch_unwind from the harness if we set up a runtime with something like builder.catch_unwind(false)?

@carllerche
Copy link
Member

In theory, I am OK w/ the idea of adding a catch_unwind configuration to the runtime builder. However, implementing this would not be trivial for the multi-threaded scheduler. The scheduler must maintain correctness, so the panic must be caught, the runtime cleanly shutdown, and the panic bubbled up to the caller. Of course, what is the "caller"? Is it block_on? If so, which block_on is it? There can be multiple concurrent calls to Runtime::block_on.

I would read a proposal.

@kstrafe
Copy link

kstrafe commented Dec 4, 2020

@carllerche would it be acceptable to panic when building a multi-threaded scheduler that has been configured to not catch_unwind?

@Darksonn
Copy link
Contributor Author

Darksonn commented Dec 4, 2020

It's also not obvious for the current thread scheduler. That scheduler can also have multiple concurrent calls to block_on.

@kstrafe
Copy link

kstrafe commented Dec 4, 2020

Since it's only useful for testing atm, why not let that be unspecified, and let the particular thread that happens to run into the panic just panic?

@MikailBag
Copy link
Contributor

MikailBag commented Dec 5, 2020

Alternatively, a new TestRuntime(tiny wrapper for single thread Runtime) can be introduced that
a) only allows single block_on
b) propagates panicks in tasks
And tokio::tes macro can use this TestRuntime in the expansion

@nashley
Copy link

nashley commented Jun 28, 2022

Has anything changed on this front? Do tests still need to join/try_join each task's handle in order to catch panics?
It'd be nice if this was a warning at least.

@Darksonn
Copy link
Contributor Author

For the case of panics, #4770 was recently merged, but it's not yet released.

@Darksonn
Copy link
Contributor Author

Closing in favor of #4516.

@Ekleog
Copy link
Contributor

Ekleog commented Jan 3, 2024

It seems to me like #4516 is (implemented on tokio_unstable, and) focusing mostly on a generic mechanism to make unhandled panics have some behavior.

I'm thinking tokio::test should just default to having all panics trigger a test failure. As a consequence, it'd become possible to more easily test multi-task setups, without requiring the tokio_unstable flag as tokio::test would just default to this behavior.

OTOH, it does mean a change in behavior for tokio::test, which in itself could be considered semver-breaking, though I'd argue it's actually a bugfix.

That said, if you think it doesn't make sense I won't insist. Just wanted to raise the point that #4516 is neither necessary nor sufficient to stabilize for this to work better for testing use cases :)

@Darksonn
Copy link
Contributor Author

Darksonn commented Jan 3, 2024

OTOH, it does mean a change in behavior for tokio::test, which in itself could be considered semver-breaking, though I'd argue it's actually a bugfix.

It's way too breaking of a change to make that argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate A-tokio-test Area: The tokio-test crate C-musing Category: musings about a better world M-runtime Module: tokio/runtime
Projects
None yet
Development

No branches or pull requests

7 participants