Michael Friend
04/08/2020, 4:11 PM@Test
fun eternalTest() = testCoroutineRule.testDispatcher.runBlockingTest {
launch {
while (isActive) {
delay(1000)
}
}
Assert.fail()/throw Exception/verify(...)
}
My expectation is that the exception from an assertion failure or otherwise would cancel the testCoroutineScope which then cancels all children, including the code inside launch. What actually happens is that the job in the launch is never cancelled and continues forever, causing runBlockingTest to hang forever. Unless the coroutine test library is injecting a SupervisorJob
into testCoroutineScope somewhere the cancellation should be propagated. Am i missing something and if not, does anyone know of a workaround?Assert.fail
is called, only printing 5 dots
@Test
fun test() {
runBlocking {
launch {
while (isActive) {
delay(100)
println(".")
}
}
delay(500)
Assert.fail()
}
}