https://kotlinlang.org logo
#coroutines
Title
# coroutines
j

jeggy

06/11/2020, 9:29 AM
I started using
runBlockingTest
and am now getting:
java.lang.IllegalStateException: This job has not completed yet
Is there some nice way to figure out which job has not been completed? Or do I need to find that out myself?
a

allan.conda

06/11/2020, 9:37 AM
can you share the method to test? you might need to inject a testdispatcher or just use runBlocking{}
j

jeggy

06/11/2020, 9:43 AM
I'm trying to figure out where I'm leaking some coroutines here: https://github.com/aPureBase/KGraphQL/blob/4a69f9ff4cdfb844fc6f4f0480bef2667fa060e9/kgraphql/src/test/kotlin/com/apurebase/kgraphql/DataLoaderTest.kt#L504 This is a function that creates a lot of coroutines recursively, and I want to be 100% sure that there are no coroutines lost somewhere, but it seems like there currently is.
If injecting a testdispatcher will help I will do that 🙂
z

Zach Klippenstein (he/him) [MOD]

06/11/2020, 1:51 PM
Are you naming your coroutines? If you're doing that, then you could make an exception breakpoint that matches that message and probably inspect the coroutine context around where it's getting thrown.
👍 1
j

jeggy

06/11/2020, 2:54 PM
Thanks I will try naming all my coroutines and see if I figure out how to pinpoint the problem. I've never named any coroutines before. Is this the correct way to do that?
Copy code
launch(CoroutineName("this-coroutine-name")) {
    println("Hello World")
}
👌 1
z

Zach Klippenstein (he/him) [MOD]

06/11/2020, 3:15 PM
Yep!
2 Views