Vsevolod Tolstopyatov [JB]
12/22/2021, 12:47 PMkotlinx-coroutines-test
module with reworked API and multiplatform support
• CoroutineDispatcher.limitedParallelism
and elastic <http://Dispathers.IO|Dispathers.IO>
• Out-of-the-box support of new K/N memory model
• CopyableThreadContextElement
for mutable context elements
• And a lot of improvements and bug fixes: https://github.com/Kotlin/kotlinx.coroutines/releases/tag/1.6.0
We also have a blogpost and video with additional details, examples and explanationnative-mt
version is also here, and this is the last major version of coroutines with the support of native-mt
builds: https://github.com/Kotlin/kotlinx.coroutines/issues/462#issuecomment-999557659Orhan Tozan
12/22/2021, 2:44 PMrusshwolf
12/22/2021, 4:53 PMPaul Woitaschek
12/23/2021, 10:22 AM@Test
fun myTest() = runTest {
flow {
delay(10.milliseconds)
emit(Unit)
}.test {
awaitItem() shouldBe Unit
}
}
Dmitry Khalanskiy [JB]
12/23/2021, 10:40 AMcollect
of this flow in Dispatchers.Unconfined
, which is not linked to `kotlinx-coroutines-test`: https://github.com/cashapp/turbine/blob/trunk/src/commonMain/kotlin/app/cash/turbine/FlowTurbine.kt#L86
So, the timeout runs with delay-skipping, whereas the flow body does not.
I would suggest turning off the timeout, as our test framework will also fail if the system hangs.
@Test
fun myTest() = runTest {
flow {
yield()
delay(10.milliseconds)
emit(Unit)
}.test(0) {
assertEquals(Unit, awaitItem())
}
}
test
is typically used. I think the long-term solution would be to ask Turbine to allow passing a dispatcher in which the flow should be collected. If this is done, passing an UnconfinedTestDispatcher
there would make the flow aware of the delay-skipping.Paul Woitaschek
12/23/2021, 10:50 AMDmitry Khalanskiy [JB]
12/23/2021, 10:52 AMPaul Woitaschek
12/23/2021, 10:55 AMDmitry Khalanskiy [JB]
12/23/2021, 11:01 AM@Test
fun myTest() = runTest {
flow {
delay(10.milliseconds)
emit(Unit)
}.flowOn(UnconfinedTestDispatcher(testScheduler))
.test {
assertEquals(Unit, awaitItem())
}
}
Paul Woitaschek
12/23/2021, 11:05 AM