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

Make dispatchers overriding for DODW publicly available and resettable #41

Merged
merged 3 commits into from
Oct 27, 2023

Conversation

gmk57
Copy link
Contributor

@gmk57 gmk57 commented Oct 26, 2023

DataObservableDelegateWrapperDispatchers was initially marked as internal because I wasn't sure it's really needed: typical DOD usage was already testable synchronously thanks to Dispatchers.Unconfined in fromNetwork.

But recently we hit the case where fromNetwork contains internal loop with delays to implement polling. These delays are not skippable without injecting some TestDispatcher.

We should also provide the means to reset dispatchers, to keep tests self-contained and independent of each other.


val delegate = DataObservableDelegateWrapper<Unit, String>(
fromNetwork = {
delay(3.seconds)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Verifies that delays are actually skipped (in combination with 1s timeout for the whole test)


DataObservableDelegateWrapperDispatchers.setDispatchers(testDispatcher)
DataObservableDelegateWrapperDispatchers.IO shouldBe testDispatcher
DataObservableDelegateWrapperDispatchers.Unconfined shouldBe testDispatcher
Copy link
Member

Choose a reason for hiding this comment

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

these are cluttering this test case IMO, if you want to test the setter/getter behaviour better be done separately

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 😄

}
networkDispatcher shouldBe testDispatcher

DataObservableDelegateWrapperDispatchers.resetDispatchers()
Copy link
Member

Choose a reason for hiding this comment

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

same here, just move out set/get/reset assertions in a separate test case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 😄

fun resetDispatchers() {
IO = Dispatchers.IO
Unconfined = Dispatchers.Unconfined
Copy link
Member

Choose a reason for hiding this comment

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

I'd reuse this method in init phase as well, not repeat IO = Dispatchers.IO / Unconfined = Dispatchers.Unconfined twice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'll need to declare the properties as lateinit, otherwise compiler is not satisfied. Do you think it's worth it?

Copy link
Member

Choose a reason for hiding this comment

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

sounds fair, unless you see any issues with that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 😄

@yatsinar yatsinar merged commit 233b7f3 into revolut-mobile:master Oct 27, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants