-
Notifications
You must be signed in to change notification settings - Fork 531
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
TestControl + Dispatcher == deadlock #4104
Comments
I'm pretty sure this is expected behavior. |
Damn, forgot about that. By any chance, is there anything that could help mitigate the issue, to help other poor souls understand that it's a no-no without spending a few hours debugging ? Could the Dispatcher somehow detect that it's being used in an improper runtime and throw a descriptive error or something ? |
First thing that comes to mind is leveraging |
Can you elaborate ? As of now, printing Then there's the question of whether you're suggesting that an ad-hoc BlockingContext would always throw (which would probably break legitimate uses in TestControl), or whether you're suggesting that the dispatcher implementation would have to inspect |
BlockContext.withBlockContext(myContext) {
// then this block runs with myContext as the handler
// for scala.concurrent.blocking
}
I am concerned about this too, but I am not entirely convinced it would break legitimate use-cases. cats-effect/testkit/shared/src/main/scala/cats/effect/testkit/TestControl.scala Lines 432 to 437 in d5a3d4c
|
Another option is we could try and side-channel this warning, but proceed. |
To elaborate on the context : I came across a deadlock whilst testing code that was integrating with a Caffeine-cache. I wanted to test the TTLs, and caffeine has a mechanism to override the clock it uses to poll time, which is basically a So yeah, I don't disagree with what you say, but it does feel like my usecase was somewhat legitimate in the context of TestControl. It's probably a XY-problem though. Maybe there could be a flavour of execute that could take a |
Oh yeah ... if I understand correctly, it would be far better to just use |
|
Actually this doesn't work 😝 if you convert to |
In fact, since this can be surprising, I wonder if we should not support translation of cats-effect/core/shared/src/main/scala/cats/effect/IO.scala Lines 2286 to 2287 in d5a3d4c
|
Ooooooh I forgot that those were cases in the ADT inside of |
I took a closer look at this and I'm afraid this idea would be too much of a footgun. Currently cats-effect/testkit/shared/src/main/scala/cats/effect/testkit/TestControl.scala Lines 370 to 373 in caee0e8
cats-effect/kernel-testkit/shared/src/main/scala/cats/effect/kernel/testkit/TestContext.scala Lines 234 to 244 in caee0e8
So this would mean that if anyone attempts to use |
Using CE 3.5.4, invoking a
Dispatcher#unsafeRunSync
in a program run withTestControl
appears to deadlockThe text was updated successfully, but these errors were encountered: