Rxjava: onErrorResumeNext onErrorReturn not called when subscribeOn any scheduler under unit test environment using 2.1

Created on 1 Jun 2017  路  4Comments  路  Source: ReactiveX/RxJava

onErrorResumeNext onErrorReturn not called when subscribeOn any schedule under unit test environment using 2.1, but they work in the actual app environment and also works on RxJava1.

What I am expecting is that the first test case should pass. Do I have wrong expectation or do somthing wrong?

Version for rxjava: 'io.reactivex.rxjava2:rxjava:2.1.0'
Version for junit: "junit:junit:4.12'

This fails

    @Test
    public void test() {
        Observable.error(() -> new RuntimeException())
                .subscribeOn(Schedulers.newThread())
                .onErrorResumeNext(Observable.just("1"))
                .test()
                .assertValueAt(0, v -> "1".equals(v));
    }

This passes
```
@Test
public void test() {
Observable.error(new RuntimeException())
.subscribeOn(Schedulers.newThread())
.onErrorResumeNext(Observable.just("1"))
.test()
.assertValueAt(0, v -> "1".equals(v));
}


**This passes**
@Test
public void test() {
    Observable.error(() -> new RuntimeException())
            .onErrorResumeNext(Observable.just("1"))
            .test()
            .assertValueAt(0, v -> "1".equals(v));
}

**trace for failed test case**

java.lang.AssertionError: No values (latch = 1, values = 0, errors = 0, completions = 0)

at io.reactivex.observers.BaseTestConsumer.fail(BaseTestConsumer.java:162)
at io.reactivex.observers.BaseTestConsumer.assertValueAt(BaseTestConsumer.java:417)
   /** hide one line of trace because of containing company information, just where the assertion failes in test class **/
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

Process finished with exit code 255
```

2.x Question

Most helpful comment

You have to wait for the sequence to finish before asserting properties when using operators that run on schedulers:

.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertResult(1);

See the other await methods.

All 4 comments

You have to wait for the sequence to finish before asserting properties when using operators that run on schedulers:

.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertResult(1);

See the other await methods.

Thanks, @akarnokd , it works for me, actually, I will choose await() in my case. And this has been already in WiKi page. Sorry for not reading it carefully, I paste the link here for anyone who may be interested.

Looks like this question has been answered. If you have further input on the issue, don't hesitate to reopen this issue or post a new one.

Nice @akarnokd !!
Works perfectly.
Thanks a lot!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wangjingling picture wangjingling  路  3Comments

midnight-wonderer picture midnight-wonderer  路  3Comments

dsvoronin picture dsvoronin  路  4Comments

nltran picture nltran  路  4Comments

dzharikhin picture dzharikhin  路  4Comments