File tree 1 file changed +14
-10
lines changed
kotlinx-coroutines-test/common/src
1 file changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -45,19 +45,23 @@ private class TestCoroutineScopeImpl(
45
45
46
46
override fun cleanupTestCoroutines () {
47
47
val delayController = coroutineContext.delayController
48
- if (delayController != null ) {
49
- delayController.cleanupTestCoroutines()
50
- coroutineContext.uncaughtExceptionCaptor.cleanupTestCoroutinesCaptor()
48
+ val hasUnfinishedJobs = if (delayController != null ) {
49
+ try {
50
+ delayController.cleanupTestCoroutines()
51
+ false
52
+ } catch (e: UncompletedCoroutinesError ) {
53
+ true
54
+ }
51
55
} else {
52
56
testScheduler.runCurrent()
53
- coroutineContext.uncaughtExceptionCaptor.cleanupTestCoroutinesCaptor()
54
- if (! testScheduler.isIdle()) {
55
- throw UncompletedCoroutinesError (
56
- " Unfinished coroutines during teardown. Ensure all coroutines are" +
57
- " completed or cancelled by your test."
58
- )
59
- }
57
+ ! testScheduler.isIdle()
60
58
}
59
+ coroutineContext.uncaughtExceptionCaptor.cleanupTestCoroutinesCaptor()
60
+ if (hasUnfinishedJobs)
61
+ throw UncompletedCoroutinesError (
62
+ " Unfinished coroutines during teardown. Ensure all coroutines are" +
63
+ " completed or cancelled by your test."
64
+ )
61
65
val jobs = coroutineContext.activeJobs()
62
66
if ((jobs - initialJobs).isNotEmpty())
63
67
throw UncompletedCoroutinesError (" Test finished with active jobs: $jobs " )
You can’t perform that action at this time.
0 commit comments