package kotlinx.coroutines.flow import kotlinx.coroutines.* import kotlin.test.* class FlatMapConcatTest : FlatMapBaseTest() { override fun Flow.flatMap(mapper: suspend (T) -> Flow): Flow = flatMapConcat(transform = mapper) @Test fun testFlatMapConcurrency() = runTest { var concurrentRequests = 0 val flow = (1..100).asFlow().flatMapConcat { value -> flow { ++concurrentRequests emit(value) delay(Long.MAX_VALUE) } } val consumer = launch { flow.collect { value -> expect(value) } } repeat(4) { yield() } assertEquals(1, concurrentRequests) consumer.cancelAndJoin() finish(2) } }