Skip to content

Commit 546dd6e

Browse files
non-deterministic testUserSubscriberUsingRequestAsync
fix non-deterministic failures of BackpressureTests.testUserSubscriberUsingRequestAsync I was able to replicate the occasional failure by putting it in a tight loop. With these changes it no longer fails.
1 parent d9c628d commit 546dd6e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

rxjava-core/src/test/java/rx/BackpressureTests.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public void onNext(Integer t) {
344344
assertEquals(20, batches.get());
345345
}
346346

347-
@Test(timeout = 2000)
347+
@Test
348348
public void testUserSubscriberUsingRequestAsync() throws InterruptedException {
349349
AtomicInteger c = new AtomicInteger();
350350
final AtomicInteger totalReceived = new AtomicInteger();
@@ -372,14 +372,20 @@ public void onError(Throwable e) {
372372
public void onNext(Integer t) {
373373
int total = totalReceived.incrementAndGet();
374374
received.incrementAndGet();
375+
boolean done = false;
375376
if (total >= 2000) {
377+
done = true;
376378
unsubscribe();
377-
latch.countDown();
378379
}
379380
if (received.get() == 100) {
380381
batches.incrementAndGet();
381-
request(100);
382382
received.set(0);
383+
if (!done) {
384+
request(100);
385+
}
386+
}
387+
if (done) {
388+
latch.countDown();
383389
}
384390
}
385391

@@ -470,8 +476,8 @@ public void request(long n) {
470476
long _c = requested.getAndAdd(n);
471477
if (_c == 0) {
472478
while (!s.isUnsubscribed()) {
473-
s.onNext(i++);
474479
counter.incrementAndGet();
480+
s.onNext(i++);
475481
if (requested.decrementAndGet() == 0) {
476482
// we're done emitting the number requested so return
477483
return;

0 commit comments

Comments
 (0)