Skip to content

Commit

Permalink
Trying to fix non-deterministic test
Browse files Browse the repository at this point in the history
- not sure of a way other than putting Thread.sleep in here to give time after each CountDownLatch triggers for the process scheduler to execute the next line of each thread

See ReactiveX#201 for more information.
  • Loading branch information
benjchristensen committed Apr 2, 2013
1 parent fb555df commit 169e7e0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions rxjava-core/src/main/java/rx/operators/OperationMerge.java
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,15 @@ public void onNext(String v) {
o1.onNextBeingSent.await();
o2.onNextBeingSent.await();

// I can't think of a way to know for sure that both threads have or are trying to send onNext
// since I can't use a CountDownLatch for "after" onNext since I want to catch during it
// but I can't know for sure onNext is invoked
// so I'm unfortunately reverting to using a Thread.sleep to allow the process scheduler time
// to make sure after o1.onNextBeingSent and o2.onNextBeingSent are hit that the following
// onNext is invoked.

Thread.sleep(300);

try { // in try/finally so threads are released via latch countDown even if assertion fails
assertEquals(1, concurrentCounter.get());
} finally {
Expand Down Expand Up @@ -541,6 +550,8 @@ public Subscription subscribe(final Observer<String> observer) {
public void run() {
onNextBeingSent.countDown();
observer.onNext("hello");
// I can't use a countDownLatch to prove we are actually sending 'onNext'
// since it will block if synchronized and I'll deadlock
observer.onCompleted();
}

Expand Down

0 comments on commit 169e7e0

Please sign in to comment.