Skip to content

Fix request != 0 checking in the scalar paths of merge() #3093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/main/java/rx/internal/operators/OperatorMerge.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ void tryEmit(InnerSubscriber<T> subscriber, T value) {
if (r != 0L) {
synchronized (this) {
// if nobody is emitting and child has available requests
if (!emitting) {
r = producer.get();
if (!emitting && r != 0L) {
emitting = true;
success = true;
}
Expand Down Expand Up @@ -422,7 +423,8 @@ void tryEmit(T value) {
if (r != 0L) {
synchronized (this) {
// if nobody is emitting and child has available requests
if (!emitting) {
r = producer.get();
if (!emitting && r != 0L) {
emitting = true;
success = true;
}
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/rx/BackpressureTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,30 @@ public void testMergeAsync() {
assertTrue(c2.get() < RxRingBuffer.SIZE * 5);
}

@Test
public void testMergeAsyncThenObserveOnLoop() {
for (int i = 0; i < 500; i++) {
if (i % 10 == 0) {
System.out.println("testMergeAsyncThenObserveOnLoop >> " + i);
}
// Verify there is no MissingBackpressureException
int NUM = (int) (RxRingBuffer.SIZE * 4.1);
AtomicInteger c1 = new AtomicInteger();
AtomicInteger c2 = new AtomicInteger();

TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
Observable<Integer> merged = Observable.merge(
incrementingIntegers(c1).subscribeOn(Schedulers.computation()),
incrementingIntegers(c2).subscribeOn(Schedulers.computation()));

merged.observeOn(Schedulers.io()).take(NUM).subscribe(ts);
ts.awaitTerminalEvent();
ts.assertNoErrors();
System.out.println("testMergeAsyncThenObserveOn => Received: " + ts.getOnNextEvents().size() + " Emitted: " + c1.get() + " / " + c2.get());
assertEquals(NUM, ts.getOnNextEvents().size());
}
}

@Test
public void testMergeAsyncThenObserveOn() {
int NUM = (int) (RxRingBuffer.SIZE * 4.1);
Expand Down