Skip to content

Commit

Permalink
Fix ownJob not always completing
Browse files Browse the repository at this point in the history
  • Loading branch information
dkhalanskyjb committed Oct 27, 2021
1 parent b43b87d commit 2cddb28
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions kotlinx-coroutines-test/common/src/TestCoroutineScope.kt
Expand Up @@ -45,11 +45,13 @@ private class TestCoroutineScopeImpl(
private val initialJobs = coroutineContext.activeJobs()

override fun cleanupTestCoroutines() {
coroutineContext.uncaughtExceptionCaptor.cleanupTestCoroutinesCaptor()
coroutineContext.delayController?.cleanupTestCoroutines()
val jobs = coroutineContext.activeJobs()
if ((jobs - initialJobs).isNotEmpty()) {
val exception = UncompletedCoroutinesError("Test finished with active jobs: $jobs")
try {
coroutineContext.uncaughtExceptionCaptor.cleanupTestCoroutinesCaptor()
coroutineContext.delayController?.cleanupTestCoroutines()
val jobs = coroutineContext.activeJobs()
if ((jobs - initialJobs).isNotEmpty())
throw UncompletedCoroutinesError("Test finished with active jobs: $jobs")
} catch (exception: Throwable) {
ownJob?.completeExceptionally(exception)
throw exception
}
Expand Down

0 comments on commit 2cddb28

Please sign in to comment.