Skip to content

Commit 0a60a3b

Browse files
committed
Fix ownJob not always completing
1 parent 37d3d46 commit 0a60a3b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ private class TestCoroutineScopeImpl(
4545
private val initialJobs = coroutineContext.activeJobs()
4646

4747
override fun cleanupTestCoroutines() {
48-
coroutineContext.uncaughtExceptionCaptor.cleanupTestCoroutinesCaptor()
49-
coroutineContext.delayController?.cleanupTestCoroutines()
50-
val jobs = coroutineContext.activeJobs()
51-
if ((jobs - initialJobs).isNotEmpty()) {
52-
val exception = UncompletedCoroutinesError("Test finished with active jobs: $jobs")
48+
try {
49+
coroutineContext.uncaughtExceptionCaptor.cleanupTestCoroutinesCaptor()
50+
coroutineContext.delayController?.cleanupTestCoroutines()
51+
val jobs = coroutineContext.activeJobs()
52+
if ((jobs - initialJobs).isNotEmpty())
53+
throw UncompletedCoroutinesError("Test finished with active jobs: $jobs")
54+
} catch (exception: Throwable) {
5355
ownJob?.completeExceptionally(exception)
5456
throw exception
5557
}

0 commit comments

Comments
 (0)