-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
runBlockingTest fails with "This job has not completed yet" #1204
Comments
Thank you for this minimal repro bug report! Adding some tests for this and taking a look at getting this patched. |
as an aside if anyone else is seeing this until it gets fixed - it appears the failure is caused by the thread (the blocking call to sleep is not required) |
Patch #1206 should fix it! It turns out the behavior of completion in the presence of multiple threads had a non-deterministic outcome that could, in some cases, cause a random test result. This patch fixes the issue reported here by making it pass (as expected) while providing a detailed error message and test failure if this race condition is detected. |
…is fixed / Kotlin/kotlinx.coroutines#1206 merged and both released
Is there a workaround for this issue ? |
I came with this exception for some Room database tests (
I hope this helps! |
I'm using something like
|
@objcode I'm not sure if this patch will fix this issue entirely. E.g. this code, that uses no other threads, fails with the "This job has not completed" message"
while this code just finishes without any problems:
|
@Anton-Spaans-Intrepid I would expect that to fail as it the collect {} will never complete. In the patched version, you should see a 30 second wait followed by an error. What behavior are you expecting? |
(I just discovered I used my other GitHub account ... ah well 😄) I expect the test to never end. It will hang. |
@streetsofboston Hm, interesting. Can you elaborate on why? To me this seems like it "should" fail since you're suspending the test coroutine (the coroutine in rbt) with There's probably three options:
|
@objcode
The above test would never return. You could make the case that if a non-suspending piece of code never completes, a corresponding suspending piece of code should never resume (and when wrapping that in a Also, a 30 seconds timeout may not be enough for some tests... should the timeout be configurable? In the end, it is a matter of taste 😄 |
Any update on when this fix will be released? |
Having this issue as well, Seems it only happens if touching files in android framework or that contain livedata not quite sure... |
Happens to my tests (not using livedata). Here are the tests: https://github.com/premnirmal/StockTicker/blob/master/app/src/test/kotlin/com/github/premnirmal/ticker/network/StocksApiTest.kt |
Here is another minimal test case:
This fails with
|
I just ran into this issue. Any update on a permanent fix for the issue or suggested workarounds would be appreciated. |
Just use
fun test() = runBlocking{}
instead of TestCoroutineScope
…On Sat, Jan 11, 2020, 6:40 PM Shane Witbeck ***@***.***> wrote:
I just ran into this issue.
Any update on a permanent fix for the issue or suggested workarounds would
be appreciated.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1204?email_source=notifications&email_token=AAGZSBJMQXXQS5HWZZBYSVLQ5JRG5A5CNFSM4HNWA4R2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIWOPDQ#issuecomment-573368206>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGZSBOBG7HKCV7GUYNT5KDQ5JRG5ANCNFSM4HNWA4RQ>
.
|
Saw that workaround after I posted. Thanks! |
Having the same issue. But temporarily one can use runBlocking without having any issues |
I've run into this issue testing a long running time-line schedule. Using |
To have your test run quicker, you can implement your own testing
dispatcher, implementing Delay, where you would divide the requested time
by the desired amount.
…On Fri, Jan 24, 2020 at 12:20 PM Daniel Asher ***@***.***> wrote:
I've run into this issue testing a long running time-line schedule. Using
runBlocking is not an option for me as the test would run too long.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1204?email_source=notifications&email_token=ABVG6BIX4FDYC5ZEQYSPRVDQ7LFG7A5CNFSM4HNWA4R2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJ2POPQ#issuecomment-578090814>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABVG6BMISUFUNO2TMKTXUUTQ7LFG7ANCNFSM4HNWA4RQ>
.
|
Had to migrate to runBlocking {} due to Kotlin/kotlinx.coroutines#1204
Same issue with this as of May 12. runBlockingTest throws error with job never completed. runBlocking results in the stuck being stuck in an infinite wait after the mocks are created. EDIT: Found a way to bypass though by instead of Mocking my Mono/Flux requests. I gave it values instead so my awaitFirstOrNull method would actually return. |
Injecting dispatcher worked for me. The main point is to make sure you are using the same test dispatcher instance in the block inside For my project, we have DI library to inject dispatchers, and when you override the dispatcher in tests, make sure you are using the same instance instead of creating new instances every time you ask for a dispatcher. And then when you call I spoke more on this SO thread. |
You can get something from this issue |
runBlockingTest works for me when I switched from using |
Still encountered this issue when using Kotlin Coroutines 1.5.1/Micronaut 3.2/Kotest, I created a post on stackoverflow. |
This issue is fixed in |
I found it hard to find the official docs when searching for |
This commit introduces the new version of the test module. Please see README.md and MIGRATION.md for a thorough discussion of the changes. Fixes Kotlin#1203 Fixes Kotlin#1609 Fixes Kotlin#2379 Fixes Kotlin#1749 Fixes Kotlin#1204 Fixes Kotlin#1390 Fixes Kotlin#1222 Fixes Kotlin#1395 Fixes Kotlin#1881 Fixes Kotlin#1910 Fixes Kotlin#1772 Fixes Kotlin#1626 Fixes Kotlin#1742 Fixes Kotlin#2082 Fixes Kotlin#2102 Fixes Kotlin#2405 Fixes Kotlin#2462 Co-authored-by: Vsevolod Tolstopyatov <qwwdfsad@gmail.com>
For me doesn't work this solution. Instead the test falls into eternal processing. Here is my code:
And here is some code of my ViewModel, which i want to test:
UPD:
|
@mnewlive you should migrate to runTest |
Why? If my second test case works fine? |
Because it's deprecated and often time making wrong tests pass. |
This commit introduces the new version of the test module. Please see README.md and MIGRATION.md for a thorough discussion of the changes. Fixes Kotlin#1203 Fixes Kotlin#1609 Fixes Kotlin#2379 Fixes Kotlin#1749 Fixes Kotlin#1204 Fixes Kotlin#1390 Fixes Kotlin#1222 Fixes Kotlin#1395 Fixes Kotlin#1881 Fixes Kotlin#1910 Fixes Kotlin#1772 Fixes Kotlin#1626 Fixes Kotlin#1742 Fixes Kotlin#2082 Fixes Kotlin#2102 Fixes Kotlin#2405 Fixes Kotlin#2462 Co-authored-by: Vsevolod Tolstopyatov <qwwdfsad@gmail.com>
This simple block:
Fails with the exception:
This looks like a bug to me as it should pass.
Kotlin 1.3.31
Coroutines 1.2.1
The text was updated successfully, but these errors were encountered: