Description
While trying to test delays with turbine I noticed that trying to control virtual time didn't actually do anything. Like the test here
turbine/src/commonTest/kotlin/app/cash/turbine/FlowTest.kt
Lines 711 to 735 in fce249a
If you just remove all of the advanceTimeBy()
and runCurrent()
calls, it still passes
@Test
fun virtualTimeCanBeControlled() = runTest {
flow {
delay(5000)
emit("1")
delay(5000)
emit("2")
}.test {
expectNoEvents()
expectNoEvents()
assertEquals("1", awaitItem())
expectNoEvents()
assertEquals("2", awaitItem())
awaitComplete()
}
}
I'd expect the lack of advanceTimeBy()
calls to fail the first assertEquals()
. I think what's happening is that since awaitItem()
will yield, the TestDispatcher will advance time automatically. This makes virtual time meaningless when testing with Turbine unless all you want to do is verify ordering.
There's also another annoying problem that an awaitItem()
call will cause other coroutines in the same scope that are running a while (true) { delay(...); doSomething(...) }
to constantly spin.