From 7d004d6470829f7c8faabbad3386e31d3749ad52 Mon Sep 17 00:00:00 2001 From: Dmitry Khalanskiy Date: Tue, 26 Oct 2021 10:27:41 +0300 Subject: [PATCH] Fixes --- .../common/src/TestCoroutineScope.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/kotlinx-coroutines-test/common/src/TestCoroutineScope.kt b/kotlinx-coroutines-test/common/src/TestCoroutineScope.kt index a2962abf77..8b4d97139d 100644 --- a/kotlinx-coroutines-test/common/src/TestCoroutineScope.kt +++ b/kotlinx-coroutines-test/common/src/TestCoroutineScope.kt @@ -33,9 +33,9 @@ public interface TestCoroutineScope: CoroutineScope, UncaughtExceptionCaptor { ?: throw UnsupportedOperationException("This scope does not have a TestCoroutineScheduler linked to it") } -private class TestCoroutineScopeImpl ( +private class TestCoroutineScopeImpl( override val coroutineContext: CoroutineContext, - val ownJob: CompletableJob? + private val ownJob: CompletableJob? ): TestCoroutineScope, UncaughtExceptionCaptor by coroutineContext.uncaughtExceptionCaptor @@ -44,14 +44,16 @@ private class TestCoroutineScopeImpl ( get() = coroutineContext[TestCoroutineScheduler]!! /** These jobs existed before the coroutine scope was used, so it's alright if they don't get cancelled. */ - val initialJobs = coroutineContext.activeJobs() + private val initialJobs = coroutineContext.activeJobs() override fun cleanupTestCoroutines() { coroutineContext.uncaughtExceptionCaptor.cleanupTestCoroutinesCaptor() coroutineContext.delayController?.cleanupTestCoroutines() val jobs = coroutineContext.activeJobs() if ((jobs - initialJobs).isNotEmpty()) { - throw UncompletedCoroutinesError("Test finished with active jobs: $jobs") + val exception = UncompletedCoroutinesError("Test finished with active jobs: $jobs") + ownJob?.completeExceptionally(exception) + throw exception } ownJob?.complete() }