File tree 4 files changed +29
-4
lines changed
kotlinx-coroutines-core/common
kotlinx-coroutines-test/common
4 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -130,6 +130,7 @@ Low-level primitives for finer-grained control of coroutines.
130
130
131
131
[ kotlinx.coroutines.sync.Mutex ] : https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/index.html
132
132
[ kotlinx.coroutines.sync.Mutex.lock ] : https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/lock.html
133
+ [ kotlinx.coroutines.sync.Mutex.tryLock ] : https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/try-lock.html
133
134
134
135
<!-- - INDEX kotlinx.coroutines.channels -->
135
136
Original file line number Diff line number Diff line change @@ -12,7 +12,8 @@ import kotlin.coroutines.*
12
12
* Access uncaught coroutine exceptions captured during test execution.
13
13
*/
14
14
@Deprecated(
15
- " Consider whether the default mechanism of handling uncaught exceptions is sufficient. " +
15
+ " Deprecated for removal without a replacement. " +
16
+ " Consider whether the default mechanism of handling uncaught exceptions is sufficient. " +
16
17
" If not, try writing your own `CoroutineExceptionHandler` and " +
17
18
" please report your use case at https://github.com/Kotlin/kotlinx.coroutines/issues." ,
18
19
level = DeprecationLevel .WARNING
@@ -41,7 +42,8 @@ public interface UncaughtExceptionCaptor {
41
42
* An exception handler that captures uncaught exceptions in tests.
42
43
*/
43
44
@Deprecated(
44
- " It's better to define one's own `CoroutineExceptionHandler` if you just need to handle '" +
45
+ " Deprecated for removal without a replacement. " +
46
+ " It may be to define one's own `CoroutineExceptionHandler` if you just need to handle '" +
45
47
" uncaught exceptions without a special `TestCoroutineScope` integration." , level = DeprecationLevel .WARNING
46
48
)
47
49
public class TestCoroutineExceptionHandler :
Original file line number Diff line number Diff line change @@ -183,15 +183,19 @@ public fun createTestCoroutineScope(context: CoroutineContext = EmptyCoroutineCo
183
183
is UncaughtExceptionCaptor -> exceptionHandler
184
184
null -> {
185
185
val lock = SynchronizedObject ()
186
- CoroutineExceptionHandler { context , throwable ->
186
+ CoroutineExceptionHandler { _ , throwable ->
187
187
val reported = synchronized(lock) {
188
188
scope!! .reportException(throwable)
189
189
}
190
190
if (! reported)
191
191
throw throwable // let this exception crash everything
192
192
}
193
193
}
194
- else -> throw IllegalArgumentException (" A CoroutineExceptionHandler was passed to TestCoroutineScope" )
194
+ else -> throw IllegalArgumentException (
195
+ " A CoroutineExceptionHandler was passed to TestCoroutineScope. " +
196
+ " Please pass it as an argument to a `launch` or `async` block on an already-created scope " +
197
+ " if uncaught exceptions require special treatment."
198
+ )
195
199
}
196
200
val job: Job = context[Job ] ? : Job ()
197
201
return TestCoroutineScopeImpl (context + scheduler + dispatcher + exceptionHandler + job).also {
Original file line number Diff line number Diff line change @@ -309,6 +309,15 @@ class TestRunBlockingTest {
309
309
}
310
310
}
311
311
312
+ @Test
313
+ fun runBlockingTestBuilder_throwsOnBadHandler () {
314
+ assertFailsWith<IllegalArgumentException > {
315
+ runBlockingTest(CoroutineExceptionHandler { _, _ -> }) {
316
+
317
+ }
318
+ }
319
+ }
320
+
312
321
@Test
313
322
fun pauseDispatcher_disablesAutoAdvance_forCurrent () = runBlockingTest {
314
323
var mutable = 0
@@ -419,4 +428,13 @@ class TestRunBlockingTest {
419
428
fun testOverrideExceptionHandler () = runBlockingTest(exceptionHandler) {
420
429
assertSame(coroutineContext[CoroutineExceptionHandler ], exceptionHandler)
421
430
}
431
+
432
+ @Test
433
+ fun testOverrideExceptionHandlerError () {
434
+ assertFailsWith<IllegalArgumentException > {
435
+ runBlockingTest(CoroutineExceptionHandler { _, _ -> }) {
436
+ fail(" Unreached" )
437
+ }
438
+ }
439
+ }
422
440
}
You can’t perform that action at this time.
0 commit comments