-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathCombineStressTest.kt
53 lines (48 loc) · 1.61 KB
/
CombineStressTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* 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 org.junit.*
class CombineStressTest : TestBase() {
@Test
public fun testCancellation() = runTest {
withContext(Dispatchers.Default + CoroutineExceptionHandler { _, _ -> expectUnreached() }) {
flow {
expect(1)
repeat(1_000 * stressTestMultiplier) {
emit(it)
}
}.flatMapLatest {
combine(flowOf(it), flowOf(it)) { arr -> arr[0] }
}.collect()
finish(2)
reset()
}
}
@Test
public fun testFailure() = runTest {
val innerIterations = 100 * stressTestMultiplierSqrt
val outerIterations = 10 * stressTestMultiplierSqrt
withContext(Dispatchers.Default + CoroutineExceptionHandler { _, _ -> expectUnreached() }) {
repeat(outerIterations) {
try {
flow {
expect(1)
repeat(innerIterations) {
emit(it)
}
}.flatMapLatest {
combine(flowOf(it), flowOf(it)) { arr -> arr[0] }
}.onEach {
if (it >= innerIterations / 2) throw TestException()
}.collect()
} catch (e: TestException) {
expect(2)
}
finish(3)
reset()
}
}
}
}