BracketCove / Profiler

Apache License 2.0
64 stars 23 forks source link

RxJava2 Scheduler #3

Open awidiyadew opened 7 years ago

awidiyadew commented 7 years ago

I see in presenter you call .subscribeOn(schedulerProvider.io()).observeOn(schedulerProvider.ui()), i curious about testing and when I open ImmediateSchedulerProvider.java that schedulerProvider.ui() is actually return Schedulers.trampoline() not AndroidScheduler.mainThread() ?

BracketCove commented 7 years ago

Check out the SchedulerInjection.java class in the 'mock' and 'prod' source sets. Basically, changing between build variants allows me to not have to modify existing code when I run Tests/Production builds. This achieved simply by injecting a different kind of SchedulerProvider based on Build Variants.

When the App is running the mockDebug build variant, I want to use Schedulers.trampoline() for Unit Tests. Schedulers.trampoline() let's my Rx stuff execute Synchronously, which allows me to run it in "Unit Tests", which run on the JVM. If you try to run Unit Tests with the Schedulers from 'prod', you'll find that they won't run.

I forget the exact error, but iirc, it comes from the fact that we don't actually want to be messing with Threads on the JVM, but someone could fill in the blanks on this a bit better.