Skip to content

Commit 169e7e0

Browse files
Trying to fix non-deterministic test
- 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 #201 for more information.
1 parent fb555df commit 169e7e0

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

rxjava-core/src/main/java/rx/operators/OperationMerge.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,15 @@ public void onNext(String v) {
441441
o1.onNextBeingSent.await();
442442
o2.onNextBeingSent.await();
443443

444+
// I can't think of a way to know for sure that both threads have or are trying to send onNext
445+
// since I can't use a CountDownLatch for "after" onNext since I want to catch during it
446+
// but I can't know for sure onNext is invoked
447+
// so I'm unfortunately reverting to using a Thread.sleep to allow the process scheduler time
448+
// to make sure after o1.onNextBeingSent and o2.onNextBeingSent are hit that the following
449+
// onNext is invoked.
450+
451+
Thread.sleep(300);
452+
444453
try { // in try/finally so threads are released via latch countDown even if assertion fails
445454
assertEquals(1, concurrentCounter.get());
446455
} finally {
@@ -541,6 +550,8 @@ public Subscription subscribe(final Observer<String> observer) {
541550
public void run() {
542551
onNextBeingSent.countDown();
543552
observer.onNext("hello");
553+
// I can't use a countDownLatch to prove we are actually sending 'onNext'
554+
// since it will block if synchronized and I'll deadlock
544555
observer.onCompleted();
545556
}
546557

0 commit comments

Comments
 (0)