-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathFlowSuppressionTest.kt
50 lines (43 loc) · 1.23 KB
/
FlowSuppressionTest.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
/*
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.coroutines.exceptions
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import org.junit.*
import org.junit.Test
import kotlin.test.*
class FlowSuppressionTest : TestBase() {
@Test
fun testSuppressionForPrimaryException() = runTest {
val flow = flow {
try {
emit(1)
} finally {
throw TestException()
}
}.catch { expectUnreached() }.onEach { throw TestException2() }
try {
flow.collect()
} catch (e: Throwable) {
assertIs<TestException>(e)
assertIs<TestException2>(e.suppressed[0])
}
}
@Test
fun testSuppressionForPrimaryExceptionRetry() = runTest {
val flow = flow {
try {
emit(1)
} finally {
throw TestException()
}
}.retry { expectUnreached(); true }.onEach { throw TestException2() }
try {
flow.collect()
} catch (e: Throwable) {
assertIs<TestException>(e)
assertIs<TestException2>(e.suppressed[0])
}
}
}