Skip to content

Commit

Permalink
2.x: Fix zip not stopping the subscription upon eager error (#6488)
Browse files Browse the repository at this point in the history
  • Loading branch information
akarnokd authored May 27, 2019
1 parent 4ca7a9b commit c415b32
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public void drain() {
if (z.done && !delayError) {
Throwable ex = z.error;
if (ex != null) {
cancelled = true;
cancel();
a.onError(ex);
return;
Expand Down Expand Up @@ -224,6 +225,7 @@ boolean checkTerminated(boolean d, boolean empty, Observer<? super R> a, boolean
if (delayError) {
if (empty) {
Throwable e = source.error;
cancelled = true;
cancel();
if (e != null) {
a.onError(e);
Expand All @@ -235,11 +237,13 @@ boolean checkTerminated(boolean d, boolean empty, Observer<? super R> a, boolean
} else {
Throwable e = source.error;
if (e != null) {
cancelled = true;
cancel();
a.onError(e);
return true;
} else
if (empty) {
cancelled = true;
cancel();
a.onComplete();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1895,4 +1895,34 @@ public Integer apply(Integer a, Integer b) throws Exception {

ts.assertResult(4);
}

@Test
public void firstErrorPreventsSecondSubscription() {
final AtomicInteger counter = new AtomicInteger();

List<Flowable<?>> flowableList = new ArrayList<Flowable<?>>();
flowableList.add(Flowable.create(new FlowableOnSubscribe<Object>() {
@Override
public void subscribe(FlowableEmitter<Object> e)
throws Exception { throw new TestException(); }
}, BackpressureStrategy.MISSING));
flowableList.add(Flowable.create(new FlowableOnSubscribe<Object>() {
@Override
public void subscribe(FlowableEmitter<Object> e)
throws Exception { counter.getAndIncrement(); }
}, BackpressureStrategy.MISSING));

Flowable.zip(flowableList,
new Function<Object[], Object>() {
@Override
public Object apply(Object[] a) throws Exception {
return a;
}
})
.test()
.assertFailure(TestException.class)
;

assertEquals(0, counter.get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1428,4 +1428,34 @@ public Integer apply(Integer t1, Integer t2) throws Exception {
ps2.onNext(2);
to.assertResult(3);
}

@Test
public void firstErrorPreventsSecondSubscription() {
final AtomicInteger counter = new AtomicInteger();

List<Observable<?>> observableList = new ArrayList<Observable<?>>();
observableList.add(Observable.create(new ObservableOnSubscribe<Object>() {
@Override
public void subscribe(ObservableEmitter<Object> e)
throws Exception { throw new TestException(); }
}));
observableList.add(Observable.create(new ObservableOnSubscribe<Object>() {
@Override
public void subscribe(ObservableEmitter<Object> e)
throws Exception { counter.getAndIncrement(); }
}));

Observable.zip(observableList,
new Function<Object[], Object>() {
@Override
public Object apply(Object[] a) throws Exception {
return a;
}
})
.test()
.assertFailure(TestException.class)
;

assertEquals(0, counter.get());
}
}

0 comments on commit c415b32

Please sign in to comment.