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

2.x: Fix zip not stopping the subscription upon eager error #6488

Merged
merged 1 commit into from
May 27, 2019
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 @@ -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());
}
}