-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
The documentation for TestScope states.
If [context] provides a [Job], that job is used as a parent for the new scope.
This implies that TestScope is meant to be used inside an existing coroutine. In that case, runBlocking must be avoided to guard against possible thread starvation (c.f. #3983).
What happens now:
TestScope.runTest() currently calls createTestResult(), which translates into runBlocking on JVM and Native.
What should happen instead:
Only the top-level runTest functions should be allowed to call runBlocking. TestScope.runTest() should avoid calls to runBlocking.
Use case:
The TestBalloon test framework organizes test suites in a multi-level hierarchy, with a coroutine hierarchy mirroring the suite hierarchy. It uses TestScope.runTest to run individual tests at the lowest levels of that hierarchy, with virtual time and exception handling. TestBalloon can run tests in parallel using Dispatchers.Default. (Note: TestBalloon has its own mechanism to provide the necessary Promise to the JS-based infrastructure independent of TestScope.runTest().)
Users of TestBalloon have experienced thread starvation with parallel test invocation in conjunction with TestScope. Disabling TestScope did not show thread starvation. If a reproducer is required, we could work to provide one.