Skip to content

Commit ea8677d

Browse files
committed
Mention TestScope.backgroundScope in runTest timeout messages
The new message is added when the test body finishes in time, but the child coroutines don't. Fixes #4182
1 parent 5e03ca2 commit ea8677d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

kotlinx-coroutines-test/common/src/TestBuilders.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,13 @@ public fun TestScope.runTest(
340340
var message = "After waiting for $timeout"
341341
if (completionCause == null)
342342
message += ", the test coroutine is not completing"
343-
if (activeChildren.isNotEmpty())
343+
if (activeChildren.isNotEmpty()) {
344344
message += ", there were active child jobs: $activeChildren"
345-
if (completionCause != null && activeChildren.isEmpty()) {
345+
if (completionCause != null) {
346+
message += ". Use `TestScope.backgroundScope` " +
347+
"to launch the coroutines that need to be cancelled when the test body finishes"
348+
}
349+
} else if (completionCause != null) {
346350
message += if (scope.isCompleted)
347351
", the test coroutine completed"
348352
else

0 commit comments

Comments
 (0)