Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dkhalanskyjb committed Oct 26, 2021
1 parent 4cdda36 commit 7d004d6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions kotlinx-coroutines-test/common/src/TestCoroutineScope.kt
Expand Up @@ -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
Expand All @@ -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()
}
Expand Down

0 comments on commit 7d004d6

Please sign in to comment.