Skip to content

Commit d403f69

Browse files
Merge pull request ReactiveX#1527 from mattrjacobs/reduce-fails-on-backpressure
Failing unit test for reduce, showing it does not implement backpressure correctly
2 parents 27a56dc + 46290b8 commit d403f69

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

rxjava-core/src/test/java/rx/internal/operators/OperatorReduceTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package rx.internal.operators;
1818

19+
import static org.junit.Assert.assertEquals;
1920
import static org.mockito.Matchers.any;
2021
import static org.mockito.Mockito.never;
2122
import static org.mockito.Mockito.times;
@@ -114,4 +115,24 @@ public Integer call(Integer t1) {
114115
verify(observer, times(1)).onError(any(TestException.class));
115116
}
116117

118+
@Test
119+
public void testBackpressureWithNoInitialValue() throws InterruptedException {
120+
Observable<Integer> source = Observable.from(1, 2, 3, 4, 5, 6);
121+
Observable<Integer> reduced = source.reduce(sum);
122+
123+
Integer r = reduced.toBlocking().first();
124+
assertEquals(21, r.intValue());
125+
}
126+
127+
@Test
128+
public void testBackpressureWithInitialValue() throws InterruptedException {
129+
Observable<Integer> source = Observable.from(1, 2, 3, 4, 5, 6);
130+
Observable<Integer> reduced = source.reduce(0, sum);
131+
132+
Integer r = reduced.toBlocking().first();
133+
assertEquals(21, r.intValue());
134+
}
135+
136+
137+
117138
}

0 commit comments

Comments
 (0)