use of io.reactivex.rxjava3.testsupport.TestHelper in project RxJava by ReactiveX.
the class CompletableMergeTest method mainErrorInnerErrorRace.
@Test
public void mainErrorInnerErrorRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final PublishProcessor<Integer> pp1 = PublishProcessor.create();
final PublishProcessor<Integer> pp2 = PublishProcessor.create();
TestObserverEx<Void> to = Completable.merge(pp1.map(new Function<Integer, Completable>() {
@Override
public Completable apply(Integer v) throws Exception {
return pp2.ignoreElements();
}
})).to(TestHelper.<Void>testConsumer());
pp1.onNext(1);
final Throwable ex1 = new TestException();
final Throwable ex2 = new TestException();
Runnable r1 = new Runnable() {
@Override
public void run() {
pp1.onError(ex1);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
pp2.onError(ex2);
}
};
TestHelper.race(r1, r2);
Throwable ex = to.errors().get(0);
if (ex instanceof CompositeException) {
to.assertSubscribed().assertNoValues().assertNotComplete();
errors = TestHelper.compositeList(ex);
TestHelper.assertError(errors, 0, TestException.class);
TestHelper.assertError(errors, 1, TestException.class);
} else {
to.assertFailure(TestException.class);
if (!errors.isEmpty()) {
TestHelper.assertUndeliverable(errors, 0, TestException.class);
}
}
} finally {
RxJavaPlugins.reset();
}
}
}
use of io.reactivex.rxjava3.testsupport.TestHelper in project RxJava by ReactiveX.
the class CompletableDoOnLifecycleTest method onSubscribeCrash.
@Test
public void onSubscribeCrash() throws Throwable {
TestHelper.withErrorTracking(errors -> {
@SuppressWarnings("unchecked") Consumer<? super Disposable> onSubscribe = mock(Consumer.class);
Action onDispose = mock(Action.class);
doThrow(new TestException("First")).when(onSubscribe).accept(any());
Disposable bs = Disposable.empty();
new Completable() {
@Override
protected void subscribeActual(CompletableObserver observer) {
observer.onSubscribe(bs);
observer.onError(new TestException("Second"));
observer.onComplete();
}
}.doOnLifecycle(onSubscribe, onDispose).to(TestHelper.<Integer>testConsumer()).assertFailureAndMessage(TestException.class, "First");
assertTrue(bs.isDisposed());
TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second");
verify(onSubscribe).accept(any());
verify(onDispose, never()).run();
});
}
use of io.reactivex.rxjava3.testsupport.TestHelper in project RxJava by ReactiveX.
the class FlowableDoOnLifecycleTest method onSubscribeCrash.
@Test
public void onSubscribeCrash() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final BooleanSubscription bs = new BooleanSubscription();
new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> s) {
s.onSubscribe(bs);
s.onError(new TestException("Second"));
s.onComplete();
}
}.doOnSubscribe(new Consumer<Subscription>() {
@Override
public void accept(Subscription s) throws Exception {
throw new TestException("First");
}
}).to(TestHelper.<Integer>testConsumer()).assertFailureAndMessage(TestException.class, "First");
assertTrue(bs.isCancelled());
TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second");
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.testsupport.TestHelper in project RxJava by ReactiveX.
the class ObservableTimeoutTests method onNextOnTimeoutRaceFallback.
@Test
public void onNextOnTimeoutRaceFallback() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
final TestScheduler sch = new TestScheduler();
final PublishSubject<Integer> ps = PublishSubject.create();
TestObserverEx<Integer> to = ps.timeout(1, TimeUnit.SECONDS, sch, Observable.just(2)).to(TestHelper.<Integer>testConsumer());
Runnable r1 = new Runnable() {
@Override
public void run() {
ps.onNext(1);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
sch.advanceTimeBy(1, TimeUnit.SECONDS);
}
};
TestHelper.race(r1, r2);
if (to.isTerminated()) {
int c = to.values().size();
if (c == 1) {
int v = to.values().get(0);
assertTrue("" + v, v == 1 || v == 2);
} else {
to.assertResult(1, 2);
}
} else {
to.assertValuesOnly(1);
}
}
}
use of io.reactivex.rxjava3.testsupport.TestHelper in project RxJava by ReactiveX.
the class ObservableTimeoutTests method onNextOnTimeoutRace.
@Test
public void onNextOnTimeoutRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
final TestScheduler sch = new TestScheduler();
final PublishSubject<Integer> ps = PublishSubject.create();
TestObserverEx<Integer> to = ps.timeout(1, TimeUnit.SECONDS, sch).to(TestHelper.<Integer>testConsumer());
Runnable r1 = new Runnable() {
@Override
public void run() {
ps.onNext(1);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
sch.advanceTimeBy(1, TimeUnit.SECONDS);
}
};
TestHelper.race(r1, r2);
if (to.values().size() != 0) {
if (to.errors().size() != 0) {
to.assertFailure(TimeoutException.class, 1);
to.assertErrorMessage(timeoutMessage(1, TimeUnit.SECONDS));
} else {
to.assertValuesOnly(1);
}
} else {
to.assertFailure(TimeoutException.class);
to.assertErrorMessage(timeoutMessage(1, TimeUnit.SECONDS));
}
}
}
Aggregations