Skip to content

Commit e37d1a7

Browse files
authored
1.x: fix Completable.onErrorResumeNext unsubscribe not propagated (#5225)
1 parent 1d7edee commit e37d1a7

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

src/main/java/rx/Completable.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,7 @@ public final Completable onErrorResumeNext(final Func1<? super Throwable, ? exte
17291729
@Override
17301730
public void call(final rx.CompletableSubscriber s) {
17311731
final SerialSubscription sd = new SerialSubscription();
1732+
s.onSubscribe(sd);
17321733
unsafeSubscribe(new rx.CompletableSubscriber() {
17331734

17341735
@Override
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* Copyright 2016 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package rx.internal.operators;
18+
19+
import static org.junit.Assert.*;
20+
import org.junit.Test;
21+
22+
import rx.Completable;
23+
import rx.functions.Func1;
24+
import rx.observers.AssertableSubscriber;
25+
import rx.subjects.PublishSubject;
26+
27+
public class CompletableOnErrorXTest {
28+
29+
@Test
30+
public void nextUnsubscribe() {
31+
PublishSubject<Integer> ps = PublishSubject.create();
32+
33+
AssertableSubscriber<Void> as = ps.toCompletable()
34+
.onErrorResumeNext(new Func1<Throwable, Completable>() {
35+
@Override
36+
public Completable call(Throwable e) {
37+
return Completable.complete();
38+
}
39+
})
40+
.test();
41+
42+
assertTrue(ps.hasObservers());
43+
44+
as.unsubscribe();
45+
46+
assertFalse("Still subscribed!", ps.hasObservers());
47+
}
48+
49+
@Test
50+
public void completeUnsubscribe() {
51+
PublishSubject<Integer> ps = PublishSubject.create();
52+
53+
AssertableSubscriber<Void> as = ps.toCompletable()
54+
.onErrorComplete()
55+
.test();
56+
57+
assertTrue(ps.hasObservers());
58+
59+
as.unsubscribe();
60+
61+
assertFalse("Still subscribed!", ps.hasObservers());
62+
}
63+
}

0 commit comments

Comments
 (0)