Skip to content

Commit 8654393

Browse files
authored
2.x: Fix flaky sample() backpressure test, improve coverage (#6254)
1 parent 2fb9504 commit 8654393

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

src/test/java/io/reactivex/internal/operators/flowable/FlowableSampleTest.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
package io.reactivex.internal.operators.flowable;
1515

16+
import static org.junit.Assert.assertFalse;
1617
import static org.mockito.ArgumentMatchers.any;
1718
import static org.mockito.Mockito.*;
1819

@@ -306,11 +307,20 @@ public void backpressureOverflow() {
306307

307308
@Test
308309
public void backpressureOverflowWithOtherPublisher() {
309-
BehaviorProcessor.createDefault(1)
310-
.sample(Flowable.timer(1, TimeUnit.MILLISECONDS))
311-
.test(0L)
312-
.awaitDone(5, TimeUnit.SECONDS)
313-
.assertFailure(MissingBackpressureException.class);
310+
PublishProcessor<Integer> pp1 = PublishProcessor.create();
311+
PublishProcessor<Integer> pp2 = PublishProcessor.create();
312+
313+
TestSubscriber<Integer> ts = pp1
314+
.sample(pp2)
315+
.test(0L);
316+
317+
pp1.onNext(1);
318+
pp2.onNext(2);
319+
320+
ts.assertFailure(MissingBackpressureException.class);
321+
322+
assertFalse(pp1.hasSubscribers());
323+
assertFalse(pp2.hasSubscribers());
314324
}
315325

316326
@Test
@@ -455,5 +465,19 @@ public Flowable<Object> apply(Flowable<Object> f)
455465
return f.sample(1, TimeUnit.SECONDS);
456466
}
457467
});
468+
469+
TestHelper.checkDoubleOnSubscribeFlowable(new Function<Flowable<Object>, Flowable<Object>>() {
470+
@Override
471+
public Flowable<Object> apply(Flowable<Object> f)
472+
throws Exception {
473+
return f.sample(PublishProcessor.create());
474+
}
475+
});
476+
}
477+
478+
@Test
479+
public void badRequest() {
480+
TestHelper.assertBadRequestReported(PublishProcessor.create()
481+
.sample(PublishProcessor.create()));
458482
}
459483
}

0 commit comments

Comments
 (0)