-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Introduce test module with testable main dispatcher #749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
core/kotlinx-coroutines-core-test/src/MainDispatcherInjector.kt
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API needs careful design. I personally don't like the public API to mutate the dispatcher -- neither its name MainDispatcherInjector
(it does not inject anything, it just sets the global static variable), nor the very fact of its existence, even if this is only a test module.
Let's discuss the actual use-cases and see if they can be covered in a static way with an implementation of dispatcher that provides the necessarily functionality without exposing globally-mutating API.
69dc390
to
eaf9b7c
Compare
bc68d63
to
3179683
Compare
Meanwhile #810 |
8e2ac2b
to
b8e5e47
Compare
…her in uninitialized state, use Dispatchers.Main everywhere. Deprecate HandlerDispatcher.Main (was accessible only fom Java API)
* Make it extension on Dispatchers object * Move implementation details of Dispatchers to internal package * Try to instantiate original dispatcher after reset, do not cache failures * Add module with Android tests which use both Unconfined and Robolectrics * Rename module to coroutines-test
Feeling slightly sick, will proofread it again tomorrow/on Monday |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great!
Added some review notes on the current implementation. Overall this solves the issue I raised in #568 very nicely!
I've been getting a lot of questions about how to do this from Android developers and want to share this is a great solution to their problem.
core/kotlinx-coroutines-test/src/internal/MainTestDispatcher.kt
Outdated
Show resolved
Hide resolved
core/kotlinx-coroutines-test/src/internal/MainTestDispatcher.kt
Outdated
Show resolved
Hide resolved
...otlinx-coroutines-android/android-unit-tests/test/ordered/tests/CustomizedRobolectricTest.kt
Outdated
Show resolved
Hide resolved
@objcode thanks for the review! |
* TestDispatchersKt -> TestDispatchers * Advice to use Dispatchers.setMain if AndroidDispatcherFactory throws an exception * Fail fast in all MissingCoroutineDispatcher methods
core/kotlinx-coroutines-test/src/internal/MainTestDispatcher.kt
Outdated
Show resolved
Hide resolved
core/kotlinx-coroutines-test/src/internal/MainTestDispatcher.kt
Outdated
Show resolved
Hide resolved
core/kotlinx-coroutines-test/src/internal/MainTestDispatcher.kt
Outdated
Show resolved
Hide resolved
60405ed
to
2db3d36
Compare
TODO: add dependency to |
2db3d36
to
5d20ee3
Compare
# Conflicts: # README.md # RELEASE.md # binary-compatibility-validator/build.gradle # core/README.md # knit/resources/knit.properties # settings.gradle
I am expecting this module to be developed in the nearest future, adding support for a virtual time, our
expect
-like mechanism and debug agent.