Explore paused
mode only for TestCoroutineDispatcher.
#3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Trying out removing the immediate mode API from TestCoroutineDispatcher and relying on runBlockingTest's event loop to pump the test lambda.
Overall, change seems like it might be heading the right direction with a large API surface reduction.
However, the automatic time advancement for the main test lambda is still present which has been fairly confusing to developers.
Things that are better
order execution in other event loops (e.g. Android Main thread) are resolved
Things that are neutral
DelayController.waitForDispatcherBusy(timeoutMillis)
developers can now interact with multithreading calls directly fromTestCoroutineDispatcher
. This API is not required for the runBlockingTest usage. This is important for some major parts of Android where thread checks are explict and must be satisfied. However, the API is less than obvious and it tends toward coupling tests with impl. details (possibly of transitive dependencies).Things that are worse
runCurrent
to execute the body of the coroutine.withContext
depends on if the dispatcher's are equal. If so, no dispatch happens and no additional API calls are required. If they are not equal, then a call towaitForDispatcherBusy
/runCurrent
is required when usingTestCoroutineDispatcher
. This is alleviated inrunBlockingTest
since the execution order of theadvanceTimeUntilIdle
will join thewithContext
coroutine before continuing the test.waitForDispatcherBusy
after every function that callswithContext
is not a safe invocation. It will timeout and throw an exception in some invocations. This is a confusing API. How to cleanup?