Jag
07/14/2019, 4:55 AMrunBlockingTest
but it seems to eagerly execute despite invoking pauseDispatcher()
I tried out the sample provided on the kotlinx-coroutines-test documentation but still hitting similar problems. I’m wondering if there’s just something I’m overlooking here?
Here’s what I’m running from the documentation sample:
@Test
fun testFooWithPauseDispatcher() = runBlockingTest {
pauseDispatcher {
foo() // <-- this is still eagerly executed
// the coroutine started by foo has not run yet
// runCurrent() // the coroutine started by foo advances to delay(1_000)
// the coroutine started by foo has called println(1), and is suspended on delay(1_000)
// advanceTimeBy(1_000) // progress time, this will cause the delay to resume
// the coroutine started by foo has called println(2) and has completed here
}
}
fun CoroutineScope.foo() {
launch {
println(1) // executes after runCurrent() is called
delay(1_000) // suspends until time is advanced by at least 1_000
println(2) // executes after advanceTimeBy(1_000)
}
}
Al Warren
07/14/2019, 5:03 AMAl Warren
07/14/2019, 5:05 AMJag
07/14/2019, 5:39 AMrunBlockingTest
will drain the queue of pending operations after exiting the block, and that’s why I was seeing the output
The links provided were helpful though, thanks for sharing!