Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dkhalanskyjb committed Oct 27, 2021
1 parent bd6edd8 commit 37d3d46
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions kotlinx-coroutines-test/common/src/TestCoroutineScope.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public sealed interface TestCoroutineScope: CoroutineScope, UncaughtExceptionCap
public val testScheduler: TestCoroutineScheduler
}

private class TestCoroutineScopeImpl (
private class TestCoroutineScopeImpl(
override val coroutineContext: CoroutineContext,
val ownJob: CompletableJob?
private val ownJob: CompletableJob?
):
TestCoroutineScope,
UncaughtExceptionCaptor by coroutineContext.uncaughtExceptionCaptor
Expand All @@ -42,14 +42,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()
}
Expand Down

0 comments on commit 37d3d46

Please sign in to comment.