Skip to content
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
merged 8 commits into from
May 28, 2020

Conversation

BenHenning
Copy link
Member

@BenHenning BenHenning commented Apr 1, 2020

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).

@BenHenning BenHenning changed the title Introduce test coroutine dispatchers [DO NOT MERGE] Partially fix #89: Introduce test coroutine dispatchers [DO NOT MERGE] Apr 1, 2020
@BenHenning BenHenning marked this pull request as draft May 9, 2020 23:53
@BenHenning BenHenning marked this pull request as ready for review May 20, 2020 08:42
@BenHenning BenHenning changed the title Partially fix #89: Introduce test coroutine dispatchers [DO NOT MERGE] Partially fix #89: Introduce test coroutine dispatchers (early testing utility) May 20, 2020
Copy link
Contributor

@rt4914 rt4914 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

@rt4914 rt4914 assigned BenHenning and unassigned rt4914 May 21, 2020
Copy link
Contributor

@vinitamurthi vinitamurthi left a 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

@vinitamurthi vinitamurthi removed their assignment May 21, 2020
@BenHenning
Copy link
Member Author

Thanks everyone!

@BenHenning BenHenning merged commit 6f31261 into develop May 28, 2020
@BenHenning BenHenning deleted the introduce-test-coroutine-dispatchers branch May 28, 2020 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants