rxdart
rxdart copied to clipboard
Stream tests lack time manipulation
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.
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.
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.
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
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
I think tests should be easy to setup, zones can get cumbersome to manipulate. The clock package should be better IMO.
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.