@Test
fun test() = runBlockingTest {
val job = launch {
launch { delay(1000) }
launch { delay(1000) }
}
delay(100)
job.cancel()
// then
advanceUntilIdle()
assertEquals(100, currentTime) // Should be true, because after 100 everything is cancelled,
// but it says expected:<100> but was:<1000>
}
I respect both ways, but this one seems more intuitive for me. It is like one coroutine is running, and another is observing it.
j
Joffrey
11/16/2021, 11:48 AM
Yeah in any case both should work I believe. Either I'm missing something or this is a bug
m
marcinmoskala
11/16/2021, 1:40 PM
You mean the code snippet? I think of it as a limitation. I imagine that TestCoroutineDispatcher has a list of registered delays it needs to wait for. The problem is that when a coroutine is cancelled, a registered element is not eliminated from this list. It could be, and it would simplify testing.