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 timeout with fallback not cancelling the main source #4945

Merged
merged 1 commit into from
Dec 29, 2016
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 @@ -137,7 +137,7 @@ static final class MulticastProcessor<T> extends Flowable<T> implements Subscrib
final AtomicReference<MulticastSubscription<T>[]> subscribers;

final int prefetch;

final int limit;

final boolean delayError;
Expand All @@ -150,7 +150,7 @@ static final class MulticastProcessor<T> extends Flowable<T> implements Subscrib

volatile boolean done;
Throwable error;

int consumed;

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -319,11 +319,11 @@ void drain() {
int missed = 1;

SimpleQueue<T> q = queue;

int upstreamConsumed = consumed;
int localLimit = limit;
boolean canRequest = sourceMode != QueueSubscription.SYNC;

for (;;) {
MulticastSubscription<T>[] array = subscribers.get();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public void onComplete() {
public void dispose() {
worker.dispose();
DisposableHelper.dispose(timer);
s.cancel();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public void onComplete() {
public void dispose() {
worker.dispose();
DisposableHelper.dispose(this);
s.dispose();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ public Publisher<Integer> apply(Flowable<Integer> v) throws Exception {
public boolean test(Integer w) throws Exception {
return w % 2 == 0;
}
}),
}),
v.filter(new Predicate<Integer>() {
@Override
public boolean test(Integer w) throws Exception {
Expand All @@ -500,7 +500,7 @@ public Publisher<Integer> apply(Flowable<Integer> v) throws Exception {
public boolean test(Integer w) throws Exception {
return w % 2 == 0;
}
}),
}),
v.filter(new Predicate<Integer>() {
@Override
public boolean test(Integer w) throws Exception {
Expand Down Expand Up @@ -528,7 +528,7 @@ public Publisher<Integer> apply(Flowable<Integer> v) throws Exception {
public boolean test(Integer w) throws Exception {
return w % 2 == 0;
}
}),
}),
v.filter(new Predicate<Integer>() {
@Override
public boolean test(Integer w) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,4 +483,39 @@ protected void subscribeActual(Subscriber<? super Integer> observer) {
}
}


@Test
public void timedTake() {
PublishProcessor<Integer> ps = PublishProcessor.create();

TestSubscriber<Integer> to = ps.timeout(1, TimeUnit.DAYS)
.take(1)
.test();

assertTrue(ps.hasSubscribers());

ps.onNext(1);

assertFalse(ps.hasSubscribers());

to.assertResult(1);
}

@Test
public void timedFallbackTake() {
PublishProcessor<Integer> ps = PublishProcessor.create();

TestSubscriber<Integer> to = ps.timeout(1, TimeUnit.DAYS, Flowable.just(2))
.take(1)
.test();

assertTrue(ps.hasSubscribers());

ps.onNext(1);

assertFalse(ps.hasSubscribers());

to.assertResult(1);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

package io.reactivex.internal.operators.flowable;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

Expand Down Expand Up @@ -509,4 +509,40 @@ protected void subscribeActual(Subscriber<? super Integer> observer) {
.test()
.assertResult(1);
}

@Test
public void selectorTake() {
PublishProcessor<Integer> ps = PublishProcessor.create();

TestSubscriber<Integer> to = ps
.timeout(Functions.justFunction(Flowable.never()))
.take(1)
.test();

assertTrue(ps.hasSubscribers());

ps.onNext(1);

assertFalse(ps.hasSubscribers());

to.assertResult(1);
}

@Test
public void selectorFallbackTake() {
PublishProcessor<Integer> ps = PublishProcessor.create();

TestSubscriber<Integer> to = ps
.timeout(Functions.justFunction(Flowable.never()), Flowable.just(2))
.take(1)
.test();

assertTrue(ps.hasSubscribers());

ps.onNext(1);

assertFalse(ps.hasSubscribers());

to.assertResult(1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -481,4 +481,38 @@ protected void subscribeActual(Observer<? super Integer> observer) {
RxJavaPlugins.reset();
}
}

@Test
public void timedTake() {
PublishSubject<Integer> ps = PublishSubject.create();

TestObserver<Integer> to = ps.timeout(1, TimeUnit.DAYS)
.take(1)
.test();

assertTrue(ps.hasObservers());

ps.onNext(1);

assertFalse(ps.hasObservers());

to.assertResult(1);
}

@Test
public void timedFallbackTake() {
PublishSubject<Integer> ps = PublishSubject.create();

TestObserver<Integer> to = ps.timeout(1, TimeUnit.DAYS, Observable.just(2))
.take(1)
.test();

assertTrue(ps.hasObservers());

ps.onNext(1);

assertFalse(ps.hasObservers());

to.assertResult(1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

package io.reactivex.internal.operators.observable;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

Expand Down Expand Up @@ -510,4 +510,40 @@ protected void subscribeActual(Observer<? super Integer> observer) {
.test()
.assertResult(1);
}

@Test
public void selectorTake() {
PublishSubject<Integer> ps = PublishSubject.create();

TestObserver<Integer> to = ps
.timeout(Functions.justFunction(Observable.never()))
.take(1)
.test();

assertTrue(ps.hasObservers());

ps.onNext(1);

assertFalse(ps.hasObservers());

to.assertResult(1);
}

@Test
public void selectorFallbackTake() {
PublishSubject<Integer> ps = PublishSubject.create();

TestObserver<Integer> to = ps
.timeout(Functions.justFunction(Observable.never()), Observable.just(2))
.take(1)
.test();

assertTrue(ps.hasObservers());

ps.onNext(1);

assertFalse(ps.hasObservers());

to.assertResult(1);
}
}