<lambda>null1package kotlinx.coroutines 2 3 import kotlinx.coroutines.testing.* 4 import kotlinx.coroutines.flow.* 5 import org.junit.* 6 7 class ReusableContinuationStressTest : TestBase() { 8 9 private val iterations = 1000 * stressTestMultiplierSqrt 10 11 @Test // Originally reported by @denis-bezrukov in #2736 12 fun testDebounceWithStateFlow() = runBlocking<Unit> { 13 withContext(Dispatchers.Default) { 14 repeat(iterations) { 15 launch { // <- load the dispatcher and OS scheduler 16 runStressTestOnce(1, 1) 17 } 18 } 19 } 20 } 21 22 private suspend fun runStressTestOnce(delay: Int, debounce: Int) = coroutineScope { 23 val stateFlow = MutableStateFlow(0) 24 val emitter = launch { 25 repeat(1000) { i -> 26 stateFlow.emit(i) 27 delay(delay.toLong()) 28 } 29 } 30 var last = 0 31 stateFlow.debounce(debounce.toLong()).take(100).collect { i -> 32 if (i - last > 100) { 33 last = i 34 } 35 } 36 emitter.cancel() 37 } 38 } 39