Skip to content

Proposal: Make Schedulers should be more friendly to tests #3985

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

Closed
ZacSweers opened this issue Jun 3, 2016 · 4 comments
Closed

Proposal: Make Schedulers should be more friendly to tests #3985

ZacSweers opened this issue Jun 3, 2016 · 4 comments

Comments

@ZacSweers
Copy link
Contributor

ZacSweers commented Jun 3, 2016

RxJavaPlugins.reset() was recently made public, but there was a common misconception that this would also reset schedulers. This isn't the case however since Schedulers permanently cache their resolved schedulers, so RxJavaPlugins.reset() actually doesn't help in this regard.

I'd like to propose adding a Schedulers.reset() function as well. It comes with same caveats that RxJavaPlugins.reset() has in that it's dangerous to call in live code, but it would be enormously helpful in testing. This would simply null out the cached schedulers to force a re-check the next time they're used, and thus letting you change the scheduling hook and have the new one's output propagate.

With JUnit, it could be nicely wrapped up in a rule that could be optionally dropped into test suites on the fly. Otherwise, schedulers must be set at the beginning of your whole test suite and delegate schedulers put in place that can be configured later.

If people would be open to this, I'd be happy to provide a PR. I looked for prior discussion around this but wasn't able to find any. If I missed them somewhere, please let me know.

@zsxwing
Copy link
Member

zsxwing commented Jun 3, 2016

👍 In the long term, I would like to see that RxJavaPlugins.reset() can reset static fields related to plugins.

@ZacSweers
Copy link
Contributor Author

ZacSweers commented Jun 3, 2016

Actually it wouldn't just be nulling out those fields. It would have to replace the singleton INSTANCE of Schedulers to re-trigger its constructor and evaluation of those scheduler instances. For just tests though, I still think this is a reasonable tradeoff since it's opt-in and doesn't change existing behavior by default.

@zsxwing
Copy link
Member

zsxwing commented Jun 3, 2016

@hzsweers That's what I meant :)

ZacSweers added a commit to ZacSweers/RxJava that referenced this issue Jun 3, 2016
@ZacSweers
Copy link
Contributor Author

Opened a PR in #3986 for further review

ZacSweers added a commit to ZacSweers/RxJava that referenced this issue Jun 3, 2016
ZacSweers added a commit to ZacSweers/RxJava that referenced this issue Jun 3, 2016
akarnokd pushed a commit that referenced this issue Jun 6, 2016
* Add Schedulers.reset() for better testing

Resolves #3985

* More accurate doc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants