CLOVIS
06/02/2024, 6:09 PMTestScope
itself):
• is waited on by the test (the test only finishes after they have all run)
• is printed in the dump if the timeout is reached before it finishes, and marks the test as failed
and a coroutine running the background scope (TestScope.backgroundScope
):
• is not waited on by the test
• is killed when the test finishes
However, after testing a few things, most of this seems incorrect. What I see:
• when the test function returns, all other coroutines are dumped, no matter in which scope they were launched
• the test ends right then, even if other foreground coroutines are still active
Is this the expected behavior? Is the difference between foreground and background scopes documented anywhere?
https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-scope/background-scope.html mentions:
> Failures in coroutines in this scope do not terminate the test. Instead, they are reported at the end of the test.
It doesn't mention normal termination.
I'm surprised that the test just ends successfully and dumps the coroutines when there are still coroutines running in the foreground scope. I would have expected either the test to wait for all foreground tasks, or be marked as failed because it finished because all work executed.
Is the difference just about error reporting?Awkin
06/02/2024, 6:59 PMrunTest
waits for them: https://pl.kotl.in/3W1_URKzW Do you have an example?CLOVIS
06/02/2024, 7:01 PMsimon.vergauwen
06/03/2024, 6:58 AMrunTest
, and provide a coroutine dump when timing out due to a hanging coroutine. It's really convenient to figure out why or what is hanging in the background.simon.vergauwen
06/03/2024, 6:58 AMCLOVIS
06/03/2024, 7:08 AMAwkin
06/03/2024, 7:12 AMCLOVIS
06/03/2024, 7:37 AMdelay
(according to the dump). It was started with TestScope.launch
.christophsturm
06/03/2024, 8:05 AMCLOVIS
06/03/2024, 6:39 PM