Skip to content

Commit ed30a26

Browse files
Improve testRecursiveScheduler2 determinism
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 #329
1 parent 5a6bdd4 commit ed30a26

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

rxjava-core/src/test/java/rx/concurrency/TestSchedulers.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,7 @@ public Subscription call(Scheduler scheduler, BooleanSubscription cancel) {
306306
observer.onNext(42);
307307
latch.countDown();
308308

309-
try {
310-
Thread.sleep(1);
311-
} catch (InterruptedException e) {
312-
e.printStackTrace();
313-
}
314-
309+
// this will recursively schedule this task for execution again
315310
scheduler.schedule(cancel, this);
316311

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

356-
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)
351+
// the count can be 10 or higher due to thread scheduling of the unsubscribe vs the scheduler looping to emit the count
352+
assertTrue(count.get() >= 10);
357353
assertTrue(completed.get());
358354
}
359355

0 commit comments

Comments
 (0)