Skip to content

1.x: fix filter() default-requesting and thus going unbounded #3912

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

Merged
merged 1 commit into from
May 5, 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
1 change: 1 addition & 0 deletions src/main/java/rx/internal/operators/OperatorFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static final class FilterSubscriber<T> extends Subscriber<T> {
public FilterSubscriber(Subscriber<? super T> actual, Func1<? super T, Boolean> predicate) {
this.actual = actual;
this.predicate = predicate;
request(0);
}

@Override
Expand Down
20 changes: 17 additions & 3 deletions src/test/java/rx/internal/operators/OperatorFilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import rx.*;
import rx.exceptions.*;
import rx.functions.*;
import rx.internal.util.RxRingBuffer;
import rx.internal.util.*;
import rx.observers.TestSubscriber;
import rx.subjects.PublishSubject;

Expand Down Expand Up @@ -69,7 +69,7 @@ public Boolean call(String t1) {
});

final CountDownLatch latch = new CountDownLatch(1);
TestSubscriber<String> ts = new TestSubscriber<String>() {
TestSubscriber<String> ts = new TestSubscriber<String>(0L) {

@Override
public void onCompleted() {
Expand Down Expand Up @@ -116,7 +116,7 @@ public Boolean call(Integer t1) {
});

final CountDownLatch latch = new CountDownLatch(1);
final TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {
final TestSubscriber<Integer> ts = new TestSubscriber<Integer>(0L) {

@Override
public void onCompleted() {
Expand Down Expand Up @@ -194,4 +194,18 @@ public Boolean call(Integer v) {
ts.assertError(TestException.class);
}

@Test
public void doesntRequestOnItsOwn() {
TestSubscriber<Integer> ts = TestSubscriber.create(0L);

Observable.range(1, 10).filter(UtilityFunctions.alwaysTrue()).unsafeSubscribe(ts);

ts.assertNoValues();

ts.requestMore(10);

ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
ts.assertNoErrors();
ts.assertCompleted();
}
}