It seems that `TestCoroutineDispatcher` is waiting...
# coroutines
m
It seems that
TestCoroutineDispatcher
is waiting for cancelled tasks.
Copy code
@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've created an issue here.
j
Why use
delay(100)
instead of
advanceTimeBy(100)
in your test method though?
☝️ 2
m
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
Yeah in any case both should work I believe. Either I'm missing something or this is a bug
m
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.