When using `runBlockingTest` and my test fails wi...
# coroutines
j
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
There is a known bug with runBlockingTest https://github.com/Kotlin/kotlinx.coroutines/issues/1626
j
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
It may be. But honestly I just gave up and use runBlocking instead
j
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
Well, looks like it expecting with such code. Try save launch job to a variable and await before exit from the function
j
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 ­čÖé