https://kotlinlang.org logo
Title
j

jeggy

03/29/2020, 4:02 PM
When using
runBlockingTest
and my test fails with "This job has not completed yet" what are some ways of figuring out what is causing this? I like that it does fail, but it doesn't bring any information on where the problem is.
g

gildor

03/29/2020, 4:20 PM
There is a known bug with runBlockingTest https://github.com/Kotlin/kotlinx.coroutines/issues/1626
j

jeggy

03/29/2020, 4:29 PM
You don't think it could be me having a coroutine lost somewhere resulting in my test to fail, because I didn't wait for it to finish correctly?
g

gildor

03/29/2020, 4:30 PM
It may be. But honestly I just gave up and use runBlocking instead
j

jeggy

03/29/2020, 4:31 PM
I have a problem in production where some data gets lost just sometimes, and I'm trying to figure out exactly why it happens. and I have successfully created a small test that fails sometimes with the
runBlockingTest
and I really want to figure out exactly where it goes wrong.
I have made this into an opensource project now. https://github.com/aPureBase/DeferredJsonBuilder/blob/master/src/test/kotlin/com/apurebase/deferredJson/BuilderTest.kt I have
RepeatedTest(100)
on that test, and sometimes it succeeds and sometimes I get that error
This job has not completed yet
.
g

gildor

03/29/2020, 11:32 PM
Well, looks like it expecting with such code. Try save launch job to a variable and await before exit from the function
j

jeggy

03/30/2020, 8:13 AM
I figured it out 🙂 https://github.com/aPureBase/DeferredJsonBuilder/commit/17b349b5ef2b73fe3ac35864d4bbb86a8a5e0936 Now I'm passing the context from the function caller all the way down through all jobs created.
I didn't want to wait for the
launch
to finish, because that's the point of this library, everything in there could potentially be runned one some other thread or something complicated. Everything is defined within the builder block and then it should just know when it's finished by itself. By passing the coroutineContext along did fix the issue 🙂