what does it mean if my test fails with “java.lang...
# coroutines
c
what does it mean if my test fails with “java.lang.IllegalStateException: This job has not completed yet” when i use runBlockingTest? it works with runBlocking
is that a bug in runblocking test or does it do more checks and indicate a bug in my code?
if your test works with
runBlocking
- prefer
runBlocking
as it is less complex
s
Not always a bug. I noticed this: The runBlockingTest forwards (virtual) time automatically. If your actual async/suspend code would run forever (never finish), the runBlockingTest would need to (auto)forward time to infinity (Long.MAX_VALUE). If this is the casem your test has ended without the job having finished.
E.g.
Copy code
runBlockingTest {
    val flow = callbackFlow<Int> {
        awaitClose {}
    }
    flow.collect { ... }
}
^^^ This would show that error, since the call to collect will never resume.
c
is it a problem if i create my database connection in a setup method with runBlocking, and then not close that connection in my test that uses
runBlockingTest
? i close it later in a tear down method