aboutsummaryrefslogtreecommitdiffstats
path: root/kotlinx-coroutines-core/common/test/flow/operators/FlattenConcatTest.kt
diff options
context:
space:
mode:
Diffstat (limited to 'kotlinx-coroutines-core/common/test/flow/operators/FlattenConcatTest.kt')
-rw-r--r--kotlinx-coroutines-core/common/test/flow/operators/FlattenConcatTest.kt39
1 files changed, 39 insertions, 0 deletions
diff --git a/kotlinx-coroutines-core/common/test/flow/operators/FlattenConcatTest.kt b/kotlinx-coroutines-core/common/test/flow/operators/FlattenConcatTest.kt
new file mode 100644
index 00000000..084af5b9
--- /dev/null
+++ b/kotlinx-coroutines-core/common/test/flow/operators/FlattenConcatTest.kt
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
+ */
+
+package kotlinx.coroutines.flow
+
+import kotlinx.coroutines.*
+import kotlin.test.*
+
+class FlattenConcatTest : FlatMapBaseTest() {
+
+ override fun <T> Flow<T>.flatMap(mapper: suspend (T) -> Flow<T>): Flow<T> = map(mapper).flattenConcat()
+
+ @Test
+ fun testFlatMapConcurrency() = runTest {
+ var concurrentRequests = 0
+ val flow = (1..100).asFlow().map { value ->
+ flow {
+ ++concurrentRequests
+ emit(value)
+ delay(Long.MAX_VALUE)
+ }
+ }.flattenConcat()
+
+ val consumer = launch {
+ flow.collect { value ->
+ expect(value)
+ }
+ }
+
+ repeat(4) {
+ yield()
+ }
+
+ assertEquals(1, concurrentRequests)
+ consumer.cancelAndJoin()
+ finish(2)
+ }
+}