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 concatEager to dispose sources & clean up properly. #6405

Merged
merged 1 commit into from
Feb 12, 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 @@ -176,7 +176,12 @@ void drainAndCancel() {
}

void cancelAll() {
InnerQueuedSubscriber<R> inner;
InnerQueuedSubscriber<R> inner = current;
current = null;

if (inner != null) {
inner.cancel();
}

while ((inner = subscribers.poll()) != null) {
inner.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,21 @@ public void onComplete() {

@Override
public void dispose() {
if (cancelled) {
return;
}
cancelled = true;
upstream.dispose();

drainAndDispose();
}

void drainAndDispose() {
if (getAndIncrement() == 0) {
queue.clear();
disposeAll();
do {
queue.clear();
disposeAll();
} while (decrementAndGet() != 0);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1333,4 +1333,37 @@ public void arrayDelayErrorMaxConcurrencyErrorDelayed() {

ts.assertFailure(TestException.class, 1, 2);
}

@Test
public void cancelActive() {
PublishProcessor<Integer> pp1 = PublishProcessor.create();
PublishProcessor<Integer> pp2 = PublishProcessor.create();

TestSubscriber<Integer> ts = Flowable
.concatEager(Flowable.just(pp1, pp2))
.test();

assertTrue(pp1.hasSubscribers());
assertTrue(pp2.hasSubscribers());

ts.cancel();

assertFalse(pp1.hasSubscribers());
assertFalse(pp2.hasSubscribers());
}

@Test
public void cancelNoInnerYet() {
PublishProcessor<Flowable<Integer>> pp1 = PublishProcessor.create();

TestSubscriber<Integer> ts = Flowable
.concatEager(pp1)
.test();

assertTrue(pp1.hasSubscribers());

ts.cancel();

assertFalse(pp1.hasSubscribers());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1141,4 +1141,37 @@ public void arrayDelayErrorMaxConcurrencyErrorDelayed() {

to.assertFailure(TestException.class, 1, 2);
}

@Test
public void cancelActive() {
PublishSubject<Integer> ps1 = PublishSubject.create();
PublishSubject<Integer> ps2 = PublishSubject.create();

TestObserver<Integer> to = Observable
.concatEager(Observable.just(ps1, ps2))
.test();

assertTrue(ps1.hasObservers());
assertTrue(ps2.hasObservers());

to.dispose();

assertFalse(ps1.hasObservers());
assertFalse(ps2.hasObservers());
}

@Test
public void cancelNoInnerYet() {
PublishSubject<Observable<Integer>> ps1 = PublishSubject.create();

TestObserver<Integer> to = Observable
.concatEager(ps1)
.test();

assertTrue(ps1.hasObservers());

to.dispose();

assertFalse(ps1.hasObservers());
}
}