square / RxIdler

An IdlingResource for Espresso which wraps an RxJava Scheduler.
Apache License 2.0
512 stars 43 forks source link

RxIdler throws IllegalStateException when buffer is used #6

Closed audriusKV closed 5 years ago

audriusKV commented 7 years ago

When RxJava2 operator buffer is used like this:

RxJavaPlugins.setInitIoSchedulerHandler(Rx2Idler.create("Test scheduler"));
PublishSubject subject = PublishSubject.create();

subject
        .buffer(1, TimeUnit.SECONDS, Schedulers.io())
        .subscribe();

RxIdler throws IllegalStateException:

java.lang.IllegalStateException: Already completed
  at com.squareup.rx2.idler.DelegatingIdlingResourceScheduler$ScheduledWork.run(DelegatingIdlingResourceScheduler.java:152)
  at io.reactivex.Scheduler$Worker$PeriodicTask.run(Scheduler.java:371)
  at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61)
  at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52)
  at java.util.concurrent.FutureTask.run(FutureTask.java:266)
  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
  at java.lang.Thread.run(Thread.java:764)

If this actual RxIdler issue I can provide project to reproduce this.

JakeWharton commented 7 years ago

I'm about to head on vacation. I'll try to repro at some point when I have downtime though.

On Thu, Jul 20, 2017 at 6:13 AM Audrius Karosevicius < notifications@github.com> wrote:

When RxJava2 operator buffer is used like this:

RxJavaPlugins.setInitIoSchedulerHandler(Rx2Idler.create("Test scheduler")); PublishSubject subject = PublishSubject.create();

subject .buffer(1, TimeUnit.SECONDS, Schedulers.io()) .subscribe();

RxIdler throws IllegalStateException:

java.lang.IllegalStateException: Already completed at com.squareup.rx2.idler.DelegatingIdlingResourceScheduler$ScheduledWork.run(DelegatingIdlingResourceScheduler.java:152) at io.reactivex.Scheduler$Worker$PeriodicTask.run(Scheduler.java:371) at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61) at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) at java.lang.Thread.run(Thread.java:764)

If this actual RxIdler issue I can provide project to reproduce this.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/square/RxIdler/issues/6, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEfU4YtgUPCKLxu2OzntOVs28B4aTks5sPyhEgaJpZM4Od4pl .

nhaarman commented 7 years ago

The same goes for Observable.interval, but only if initialDelay is set to 0:

Observable.interval(0, 1, SECONDS, Schedulers.computation())
              .subscribe()
W: java.lang.IllegalStateException: Already completed
W:     at com.myapp.DelegatingIdlingResourceScheduler$ScheduledWork.run(DelegatingIdlingResourceScheduler.java:152)
W:     at io.reactivex.Scheduler$Worker$PeriodicTask.run(Scheduler.java:371)
W:     at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61)
W:     at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52)
W:     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W:     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
W:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
W:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
W:     at java.lang.Thread.run(Thread.java:764)
JakeWharton commented 7 years ago

The fix is trivial but the implications are very complicated so I don't want to make it blindly. Need more time to investigate.

henorek commented 7 years ago

@JakeWharton Is there a chance that this will be fixed soon?

JakeWharton commented 7 years ago

No one is working on it at this time.

On Wed, Aug 23, 2017 at 6:46 AM Jarek Jankowski notifications@github.com wrote:

@JakeWharton https://github.com/jakewharton Is there a chance that this will be fixed soon?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/square/RxIdler/issues/6#issuecomment-324292475, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEYVW_QgIlKHbtb9nLR4eb61-wuMvks5sbAMbgaJpZM4Od4pl .

jonasfa commented 7 years ago

Is there any known workaround? @JakeWharton perhaps if you explain what the issue is, somebody will work on it?

JakeWharton commented 7 years ago

The same state machine instance gets re-scheduled instead of the underlying Runnable being wrapped in a new one. And since we only allow forward progress in the state machine, once you execute once you cannot go backwards to being un-executed again when this happens.

On Mon, Sep 11, 2017 at 10:02 AM Jonas Alves notifications@github.com wrote:

Is there any known workaround? @JakeWharton https://github.com/jakewharton perhaps if you explain what the issue is, somebody will work on it?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/square/RxIdler/issues/6#issuecomment-328538676, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEXw8SXR9UZssVlgs7hbew_d1IAMNks5shT1wgaJpZM4Od4pl .

jonasfa commented 7 years ago

@JakeWharton thanks. You also mentioned complicated implications for a possible fix. Do you remember what was that?

JakeWharton commented 7 years ago

The obvious fix is to allow the state machine to go backwards, which it wasn't designed to do, so making that trivial change probably has other effects.

On Mon, Sep 11, 2017 at 10:36 AM Jonas Alves notifications@github.com wrote:

@JakeWharton https://github.com/jakewharton thanks. You also mentioned complicated implications for a possible fix. Do you remember what was that?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/square/RxIdler/issues/6#issuecomment-328549298, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEQ_F2o8fTH5oTX4QKOpTvA0RkOeQks5shUVvgaJpZM4Od4pl .

Maragues commented 7 years ago

@nhaarman I'm seeing this issue with or without initialDelay.

In the case of interval, the first tick is emitted, but it never goes beyond that. It does print the doAfterNext statement.

In the meantime, I'm using a JUnit rule that I've used in the past, which brings its own issues but at least it doesn't crash in my scenario

You can also check https://github.com/ReactiveX/RxAndroid/issues/149

philipbjorge commented 6 years ago

Seeing this for sample as well.

athkalia commented 6 years ago

Any updates on this?

mseroczynski commented 6 years ago

Any updates?

niemandkun commented 5 years ago

Any updates?

larryng commented 5 years ago

Made a PR that I believe addresses this issue: https://github.com/square/RxIdler/pull/14

Makes the state machine go backwards for periodic work, but AFAICT it should be safe.