Skip to content

Commit 7d004d6

Browse files
committed
Fixes
1 parent 4cdda36 commit 7d004d6

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public interface TestCoroutineScope: CoroutineScope, UncaughtExceptionCaptor {
3333
?: throw UnsupportedOperationException("This scope does not have a TestCoroutineScheduler linked to it")
3434
}
3535

36-
private class TestCoroutineScopeImpl (
36+
private class TestCoroutineScopeImpl(
3737
override val coroutineContext: CoroutineContext,
38-
val ownJob: CompletableJob?
38+
private val ownJob: CompletableJob?
3939
):
4040
TestCoroutineScope,
4141
UncaughtExceptionCaptor by coroutineContext.uncaughtExceptionCaptor
@@ -44,14 +44,16 @@ private class TestCoroutineScopeImpl (
4444
get() = coroutineContext[TestCoroutineScheduler]!!
4545

4646
/** These jobs existed before the coroutine scope was used, so it's alright if they don't get cancelled. */
47-
val initialJobs = coroutineContext.activeJobs()
47+
private val initialJobs = coroutineContext.activeJobs()
4848

4949
override fun cleanupTestCoroutines() {
5050
coroutineContext.uncaughtExceptionCaptor.cleanupTestCoroutinesCaptor()
5151
coroutineContext.delayController?.cleanupTestCoroutines()
5252
val jobs = coroutineContext.activeJobs()
5353
if ((jobs - initialJobs).isNotEmpty()) {
54-
throw UncompletedCoroutinesError("Test finished with active jobs: $jobs")
54+
val exception = UncompletedCoroutinesError("Test finished with active jobs: $jobs")
55+
ownJob?.completeExceptionally(exception)
56+
throw exception
5557
}
5658
ownJob?.complete()
5759
}

0 commit comments

Comments
 (0)