Skip to content

Commit e609627

Browse files
committed
Fixes
1 parent 5ae073d commit e609627

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

kotlinx-coroutines-core/common/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ Low-level primitives for finer-grained control of coroutines.
130130

131131
[kotlinx.coroutines.sync.Mutex]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/index.html
132132
[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
133134

134135
<!--- INDEX kotlinx.coroutines.channels -->
135136

kotlinx-coroutines-test/common/src/TestCoroutineExceptionHandler.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import kotlin.coroutines.*
1212
* Access uncaught coroutine exceptions captured during test execution.
1313
*/
1414
@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. " +
1617
"If not, try writing your own `CoroutineExceptionHandler` and " +
1718
"please report your use case at https://github.com/Kotlin/kotlinx.coroutines/issues.",
1819
level = DeprecationLevel.WARNING
@@ -41,7 +42,8 @@ public interface UncaughtExceptionCaptor {
4142
* An exception handler that captures uncaught exceptions in tests.
4243
*/
4344
@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 '" +
4547
"uncaught exceptions without a special `TestCoroutineScope` integration.", level = DeprecationLevel.WARNING
4648
)
4749
public class TestCoroutineExceptionHandler :

kotlinx-coroutines-test/common/src/TestCoroutineScope.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,19 @@ public fun createTestCoroutineScope(context: CoroutineContext = EmptyCoroutineCo
183183
is UncaughtExceptionCaptor -> exceptionHandler
184184
null -> {
185185
val lock = SynchronizedObject()
186-
CoroutineExceptionHandler { context, throwable ->
186+
CoroutineExceptionHandler { _, throwable ->
187187
val reported = synchronized(lock) {
188188
scope!!.reportException(throwable)
189189
}
190190
if (!reported)
191191
throw throwable // let this exception crash everything
192192
}
193193
}
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+
)
195199
}
196200
val job: Job = context[Job] ?: Job()
197201
return TestCoroutineScopeImpl(context + scheduler + dispatcher + exceptionHandler + job).also {

kotlinx-coroutines-test/common/test/migration/TestRunBlockingTest.kt

+18
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,15 @@ class TestRunBlockingTest {
309309
}
310310
}
311311

312+
@Test
313+
fun runBlockingTestBuilder_throwsOnBadHandler() {
314+
assertFailsWith<IllegalArgumentException> {
315+
runBlockingTest(CoroutineExceptionHandler { _, _ -> }) {
316+
317+
}
318+
}
319+
}
320+
312321
@Test
313322
fun pauseDispatcher_disablesAutoAdvance_forCurrent() = runBlockingTest {
314323
var mutable = 0
@@ -419,4 +428,13 @@ class TestRunBlockingTest {
419428
fun testOverrideExceptionHandler() = runBlockingTest(exceptionHandler) {
420429
assertSame(coroutineContext[CoroutineExceptionHandler], exceptionHandler)
421430
}
431+
432+
@Test
433+
fun testOverrideExceptionHandlerError() {
434+
assertFailsWith<IllegalArgumentException> {
435+
runBlockingTest(CoroutineExceptionHandler { _, _ -> }) {
436+
fail("Unreached")
437+
}
438+
}
439+
}
422440
}

0 commit comments

Comments
 (0)