File tree Expand file tree Collapse file tree 2 files changed +26
-5
lines changed Expand file tree Collapse file tree 2 files changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -159,14 +159,24 @@ class RunTestTest {
159
159
}
160
160
}
161
161
162
- /* * Tests uncaught exceptions taking priority over dispatch timeout in error reports . */
162
+ /* * Tests uncaught exceptions being suppressed by the dispatch timeout error. */
163
163
@Test
164
164
@NoNative // TODO: timeout leads to `Cannot execute task because event loop was shut down` on Native
165
165
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
+ }
167
177
}) {
168
178
runTest(dispatchTimeoutMs = 1 ) {
169
- coroutineContext[CoroutineExceptionHandler ]!! .handleException(coroutineContext, IllegalArgumentException ( ))
179
+ coroutineContext[CoroutineExceptionHandler ]!! .handleException(coroutineContext, TestException ( " A " ))
170
180
withContext(Dispatchers .Default ) {
171
181
delay(10000 )
172
182
3
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package kotlinx.coroutines.test
6
6
7
7
import kotlinx.coroutines.*
8
8
import kotlinx.coroutines.flow.*
9
+ import kotlinx.coroutines.internal.*
9
10
import kotlin.coroutines.*
10
11
import kotlin.test.*
11
12
@@ -100,10 +101,20 @@ class RunTestLegacyScopeTest {
100
101
101
102
@Test
102
103
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
+ }
104
115
}) {
105
116
runTestWithLegacyScope(dispatchTimeoutMs = 1 ) {
106
- coroutineContext[CoroutineExceptionHandler ]!! .handleException(coroutineContext, IllegalArgumentException ( ))
117
+ coroutineContext[CoroutineExceptionHandler ]!! .handleException(coroutineContext, TestException ( " A " ))
107
118
withContext(Dispatchers .Default ) {
108
119
delay(10000 )
109
120
3
You can’t perform that action at this time.
0 commit comments