Skip to content
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

Fixing regression in mergeDelayError #1712

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
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ public void onError(Throwable e) {
boolean sendOnComplete = false;
synchronized (this) {
wip--;
if (wip == 0 && completed) {
if ((wip == 0 && completed) || (wip < 0)) {
sendOnComplete = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,27 @@
*/
package rx.internal.operators;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import rx.Observable;
import rx.Observable.OnSubscribe;
import rx.Observer;
import rx.Subscriber;
import rx.exceptions.CompositeException;
import rx.exceptions.TestException;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.*;

public class OperatorMergeDelayErrorTest {

@Mock
Expand Down Expand Up @@ -289,6 +283,35 @@ public void testMergeArrayWithThreading() {
verify(stringObserver, times(1)).onCompleted();
}

@Test(timeout=1000L)
public void testSynchronousError() {
final Observable<Observable<String>> o1 = Observable.error(new RuntimeException("unit test"));

final CountDownLatch latch = new CountDownLatch(1);
Observable.mergeDelayError(o1).subscribe(new Subscriber<String>() {
@Override
public void onCompleted() {
fail("Expected onError path");
}

@Override
public void onError(Throwable e) {
latch.countDown();
}

@Override
public void onNext(String s) {
fail("Expected onError path");
}
});

try {
latch.await();
} catch (InterruptedException ex) {
fail("interrupted");
}
}

private static class TestSynchronousObservable implements Observable.OnSubscribe<String> {

@Override
Expand Down