-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change the exception suppression invariant to work backwards:
All the benefits of the approach stay the same, but additionally, for an arbitrary flow pipeline, adding a catch operator that is not triggered will no longer change the type of resulting exception
- Loading branch information
Showing
5 changed files
with
61 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
kotlinx-coroutines-core/jvm/test/exceptions/FlowSuppressionTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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]) | ||
|
||
} | ||
} | ||
} |