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

Stream tests lack time manipulation #695

Open
feinstein opened this issue Nov 3, 2022 · 6 comments
Open

Stream tests lack time manipulation #695

feinstein opened this issue Nov 3, 2022 · 6 comments

Comments

@feinstein
Copy link
Contributor

RxJava has the ability to inject a scheduler to some streams, this way we can manipulate time in tests. If I have an interval of 5 minutes in my code, I can't test it without a very long test, or by changing my interval in the test to some milliseconds, which won't simulate 100% what's happening in the app.

The same way that Flutter tests allows us to manipulate time for testing animations, without having to actually wait for them, rxdart should give us similar controls, as other rx libraries already do.

@feinstein feinstein changed the title Interval should receive a fake clock Stream tests lack time manipulation Nov 3, 2022
@frankpepermans
Copy link
Member

You can actually use fake time already, most of the tests actually use fake async.

On my phone atm, but please take a look at the runZoned api in Dart, for example, which allows you to override timers.

@feinstein
Copy link
Contributor Author

I took a look at the source code for some streams and I can see it uses very small durations, so I assumed there was no way to inject a fake time.

@frankpepermans
Copy link
Member

Maybe cause they're already quite old then, it's been a while since I've contributed to this lib actually.

I'd try a simple case with a Zone and some Rx, if it doesn't work we could always update the inner parts, basically it should rely on the wrapping zones for timings

@hoc081098
Copy link
Collaborator

hoc081098 commented Nov 3, 2022

I think we can use clock package in rxdart, but some built-in Stream constructors don't receive any schduler, such as Stream.periodic

Sent from my 2201117TG using FastHub

@feinstein
Copy link
Contributor Author

I think tests should be easy to setup, zones can get cumbersome to manipulate. The clock package should be better IMO.

@feinstein
Copy link
Contributor Author

Also, I don't think we should reinvent the wheel, studying how RxJava solves this should be better, as the mechanism probably covers lots of use cases for asynchronous testing of reactive streams.

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

No branches or pull requests

3 participants