Skip to content

Commit b43b87d

Browse files
committed
Fixes
1 parent 6c52412 commit b43b87d

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
@@ -31,9 +31,9 @@ public sealed interface TestCoroutineScope: CoroutineScope, UncaughtExceptionCap
3131
public val testScheduler: TestCoroutineScheduler
3232
}
3333

34-
private class TestCoroutineScopeImpl (
34+
private class TestCoroutineScopeImpl(
3535
override val coroutineContext: CoroutineContext,
36-
val ownJob: CompletableJob?
36+
private val ownJob: CompletableJob?
3737
):
3838
TestCoroutineScope,
3939
UncaughtExceptionCaptor by coroutineContext.uncaughtExceptionCaptor
@@ -42,14 +42,16 @@ private class TestCoroutineScopeImpl (
4242
get() = coroutineContext[TestCoroutineScheduler]!!
4343

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

4747
override fun cleanupTestCoroutines() {
4848
coroutineContext.uncaughtExceptionCaptor.cleanupTestCoroutinesCaptor()
4949
coroutineContext.delayController?.cleanupTestCoroutines()
5050
val jobs = coroutineContext.activeJobs()
5151
if ((jobs - initialJobs).isNotEmpty()) {
52-
throw UncompletedCoroutinesError("Test finished with active jobs: $jobs")
52+
val exception = UncompletedCoroutinesError("Test finished with active jobs: $jobs")
53+
ownJob?.completeExceptionally(exception)
54+
throw exception
5355
}
5456
ownJob?.complete()
5557
}

0 commit comments

Comments
 (0)