Skip to content

Commit b488ce5

Browse files
committed
add test
1 parent bdf86fb commit b488ce5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

kotlinx-coroutines-core/common/test/flow/channels/ChannelFlowTest.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,25 @@ class ChannelFlowTest : TestBase() {
204204
myFlow.collect()
205205
finish(4)
206206
}
207+
208+
@Test
209+
fun testDoesntDispatchWhenUnnecessarilyWhenCollected() = runTest {
210+
expect(1)
211+
var subscribed = false
212+
val myFlow = flow<Int> {
213+
expect(3)
214+
subscribed = true
215+
yield()
216+
expect(5)
217+
}
218+
launch(start = CoroutineStart.UNDISPATCHED) {
219+
expect(2)
220+
myFlow.collectLatest {
221+
expectUnreached()
222+
}
223+
finish(6)
224+
}
225+
expect(4)
226+
assertTrue(subscribed)
227+
}
207228
}

0 commit comments

Comments
 (0)