-
Notifications
You must be signed in to change notification settings - Fork 548
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
Partially fix #89: Introduce test coroutine dispatchers (early testing utility) #927
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test coroutine dispatcher. This includes introducing a test-only module to contain testing dependencies.
implementation to prepare for code review.
rt4914
approved these changes
May 21, 2020
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.
LGTM, thanks.
testing/src/main/java/org/oppia/testing/TestCoroutineDispatchers.kt
Outdated
Show resolved
Hide resolved
vinitamurthi
approved these changes
May 21, 2020
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.
LGTM, I just had some questions for my own understanding
Thanks everyone! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Introduce a test coroutine dispatcher & coordination utility to guarantee determinism in Robolectric tests. This is not yet app module or Espresso compatible (that requires abstracting the main thread portion & leveraging IdlingResources, plus verifying the replacement mechanism for app module dependencies). #89 is tracking the additional work needed after this PR is submitted.
This also introduces a new testing module where test-only dependencies can live. We shouldn't over-user this yet (e.g. app test deps should stay in the app module), but this is a pattern we will make more use of in the future (especially after we move to Bazel in #59).
This solves one critical requirement for resolving #89: arranging thread execution so that it can be deterministically idled. This was used successfully in downstream tests (see #928). However, please note that this implementation is still incomplete. #89 includes additional details of what work is needed here, so integrations with this utility should be used cautiously until it has had time to be finalized.
This implementation is loosely based on Kotlin's experimental TestCoroutineDispatcher, except the implementation needed significant changes in order to work in this coordinated environment so it was effectively rewritten from the ground up using Kotlin's as a reference for how to actually continue suspended execution.
Finally, no tests were added yet since the implementation still may broadly change and certain aspects aren't trivially testable (like the fake system clock since it's not yet correctly coordinating system time in tests across all aspects of the simulated Android test environment).