Skip to content

Commit 8f78443

Browse files
committed
Fix tests to reflect the changed behavior
1 parent 5ad2246 commit 8f78443

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

kotlinx-coroutines-test/common/test/RunTestTest.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,24 @@ class RunTestTest {
159159
}
160160
}
161161

162-
/** Tests uncaught exceptions taking priority over dispatch timeout in error reports. */
162+
/** Tests uncaught exceptions being suppressed by the dispatch timeout error. */
163163
@Test
164164
@NoNative // TODO: timeout leads to `Cannot execute task because event loop was shut down` on Native
165165
fun testRunTestTimingOutAndThrowing() = testResultMap({ fn ->
166-
assertFailsWith<IllegalArgumentException> { fn() }
166+
try {
167+
fn()
168+
fail("unreached")
169+
} catch (e: UncompletedCoroutinesError) {
170+
@Suppress("INVISIBLE_MEMBER")
171+
val suppressed = unwrap(e).suppressedExceptions
172+
assertEquals(1, suppressed.size)
173+
assertIs<TestException>(suppressed[0]).also {
174+
assertEquals("A", it.message)
175+
}
176+
}
167177
}) {
168178
runTest(dispatchTimeoutMs = 1) {
169-
coroutineContext[CoroutineExceptionHandler]!!.handleException(coroutineContext, IllegalArgumentException())
179+
coroutineContext[CoroutineExceptionHandler]!!.handleException(coroutineContext, TestException("A"))
170180
withContext(Dispatchers.Default) {
171181
delay(10000)
172182
3

kotlinx-coroutines-test/jvm/test/migration/RunTestLegacyScopeTest.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package kotlinx.coroutines.test
66

77
import kotlinx.coroutines.*
88
import kotlinx.coroutines.flow.*
9+
import kotlinx.coroutines.internal.*
910
import kotlin.coroutines.*
1011
import kotlin.test.*
1112

@@ -100,10 +101,20 @@ class RunTestLegacyScopeTest {
100101

101102
@Test
102103
fun testRunTestTimingOutAndThrowing() = testResultMap({ fn ->
103-
assertFailsWith<IllegalArgumentException> { fn() }
104+
try {
105+
fn()
106+
fail("unreached")
107+
} catch (e: UncompletedCoroutinesError) {
108+
@Suppress("INVISIBLE_MEMBER")
109+
val suppressed = unwrap(e).suppressedExceptions
110+
assertEquals(1, suppressed.size)
111+
assertIs<TestException>(suppressed[0]).also {
112+
assertEquals("A", it.message)
113+
}
114+
}
104115
}) {
105116
runTestWithLegacyScope(dispatchTimeoutMs = 1) {
106-
coroutineContext[CoroutineExceptionHandler]!!.handleException(coroutineContext, IllegalArgumentException())
117+
coroutineContext[CoroutineExceptionHandler]!!.handleException(coroutineContext, TestException("A"))
107118
withContext(Dispatchers.Default) {
108119
delay(10000)
109120
3

0 commit comments

Comments
 (0)