rxdart icon indicating copy to clipboard operation
rxdart copied to clipboard

Stream tests lack time manipulation

Open feinstein opened this issue 1 year ago • 6 comments

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 avatar Nov 03 '22 04:11 feinstein

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.

frankpepermans avatar Nov 03 '22 04:11 frankpepermans

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.

feinstein avatar Nov 03 '22 04:11 feinstein

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

frankpepermans avatar Nov 03 '22 04:11 frankpepermans

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

hoc081098 avatar Nov 03 '22 06:11 hoc081098

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

feinstein avatar Nov 03 '22 07:11 feinstein

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.

feinstein avatar Nov 03 '22 07:11 feinstein