Skip to content

Commit

Permalink
Improve testRecursiveScheduler2 determinism
Browse files Browse the repository at this point in the history
Removed use of Thread.sleep and changed assertion to allow for the expected race condition between the counter loop and unsubscribe event to fix non-determinism issue reported in ReactiveX#329
  • Loading branch information
benjchristensen committed Aug 31, 2013
1 parent 5a6bdd4 commit ed30a26
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions rxjava-core/src/test/java/rx/concurrency/TestSchedulers.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,7 @@ public Subscription call(Scheduler scheduler, BooleanSubscription cancel) {
observer.onNext(42);
latch.countDown();

try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}

// this will recursively schedule this task for execution again
scheduler.schedule(cancel, this);

return cancel;
Expand Down Expand Up @@ -353,7 +348,8 @@ public void onNext(Integer args) {
fail("Timed out waiting on completion latch");
}

assertEquals(10, count.get()); // wondering if this could be 11 in a race condition (which would be okay due to how unsubscribe works ... just it would make this test non-deterministic)
// the count can be 10 or higher due to thread scheduling of the unsubscribe vs the scheduler looping to emit the count
assertTrue(count.get() >= 10);
assertTrue(completed.get());
}

Expand Down

0 comments on commit ed30a26

Please sign in to comment.