Skip to content

Commit

Permalink
add new tests suggested by @jingibus
Browse files Browse the repository at this point in the history
  • Loading branch information
mightyguava committed Sep 24, 2023
1 parent 570fe47 commit 7ba8b1f
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/commonTest/kotlin/app/cash/turbine/FlowInScopeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,16 @@ import kotlin.test.assertSame
import kotlin.test.assertTrue
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CompletionHandlerException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers.Default
import kotlinx.coroutines.cancel
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.emitAll
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.withContext

class FlowInScopeTest {
@Test fun multipleFlows() = runTestTurbine {
Expand All @@ -38,6 +30,27 @@ class FlowInScopeTest {
turbine2.awaitComplete()
}

@Test fun awaitFailsOnVirtualTime() = runTestTurbine {
assertFailsWith<AssertionError> {
flow<Nothing> {
awaitCancellation()
}.test {
awaitComplete()
}
}
}

@Test
fun awaitFailsOnDelayVirtualTime() = runTestTurbine {
assertFailsWith<AssertionError> {
flow<Nothing> {
delay(1500.milliseconds)
}.test(timeout = 1000.milliseconds) {
awaitComplete()
}
}
}

@Test
fun channelCancellation() = runTestTurbine {
kotlin.runCatching {
Expand Down

0 comments on commit 7ba8b1f

Please sign in to comment.