| 30 | import io.reactivex.rxjava3.testsupport.TestHelper; |
| 31 | |
| 32 | public class XFlatMapTest extends RxJavaTest { |
| 33 | |
| 34 | @Rule |
| 35 | public Retry retry = new Retry(5, 1000, true); |
| 36 | |
| 37 | static final int SLEEP_AFTER_CANCEL = 500; |
| 38 | |
| 39 | final CyclicBarrier cb = new CyclicBarrier(2); |
| 40 | |
| 41 | void sleep() throws Exception { |
| 42 | cb.await(); |
| 43 | try { |
| 44 | long before = System.currentTimeMillis(); |
| 45 | Thread.sleep(5000); |
| 46 | throw new IllegalStateException("Was not interrupted in time?! " + (System.currentTimeMillis() - before)); |
| 47 | } catch (InterruptedException ex) { |
| 48 | // ignored here |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | void beforeCancelSleep(TestSubscriber<?> ts) throws Exception { |
| 53 | long before = System.currentTimeMillis(); |
| 54 | Thread.sleep(50); |
| 55 | if (System.currentTimeMillis() - before > 100) { |
| 56 | ts.cancel(); |
| 57 | throw new IllegalStateException("Overslept?" + (System.currentTimeMillis() - before)); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | void beforeCancelSleep(TestObserver<?> to) throws Exception { |
| 62 | long before = System.currentTimeMillis(); |
| 63 | Thread.sleep(50); |
| 64 | if (System.currentTimeMillis() - before > 100) { |
| 65 | to.dispose(); |
| 66 | throw new IllegalStateException("Overslept?" + (System.currentTimeMillis() - before)); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | @Test |
| 71 | public void flowableFlowable() throws Exception { |
| 72 | List<Throwable> errors = TestHelper.trackPluginErrors(); |
| 73 | try { |
| 74 | TestSubscriber<Integer> ts = Flowable.just(1) |
| 75 | .subscribeOn(Schedulers.io()) |
| 76 | .flatMap(new Function<Integer, Publisher<Integer>>() { |
| 77 | @Override |
| 78 | public Publisher<Integer> apply(Integer v) throws Exception { |
| 79 | sleep(); |
| 80 | return Flowable.<Integer>error(new TestException()); |
| 81 | } |
| 82 | }) |
| 83 | .test(); |
| 84 | |
| 85 | cb.await(); |
| 86 | |
| 87 | beforeCancelSleep(ts); |
| 88 | |
| 89 | ts.cancel(); |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…