Skip to content

Commit

Permalink
2.x: Fix toFlowable(ERROR) not cancelling upon MBE (#7084)
Browse files Browse the repository at this point in the history
  • Loading branch information
akarnokd authored Sep 23, 2020
1 parent 2cb20bd commit b13a45e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void onNext(T t) {
downstream.onNext(t);
BackpressureHelper.produced(this, 1);
} else {
upstream.cancel();
onError(new MissingBackpressureException("could not emit value due to lack of requests"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@

package io.reactivex.internal.operators.flowable;

import static org.junit.Assert.*;

import org.junit.Test;
import org.reactivestreams.Publisher;

import io.reactivex.*;
import io.reactivex.exceptions.MissingBackpressureException;
import io.reactivex.functions.Function;
import io.reactivex.subjects.PublishSubject;
import io.reactivex.subscribers.TestSubscriber;

public class FlowableOnBackpressureErrorTest {

Expand Down Expand Up @@ -50,4 +55,20 @@ public Object apply(Flowable<Integer> f) throws Exception {
}
}, false, 1, 1, 1);
}

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

TestSubscriber<Integer> ts = ps.toFlowable(BackpressureStrategy.ERROR)
.test(0L);

assertTrue(ps.hasObservers());

ps.onNext(1);

assertFalse(ps.hasObservers());

ts.assertFailure(MissingBackpressureException.class);
}
}

0 comments on commit b13a45e

Please sign in to comment.