use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableTimeoutTests method shouldUnsubscribeFromUnderlyingSubscriptionOnTimeout.
@Test
public void shouldUnsubscribeFromUnderlyingSubscriptionOnTimeout() throws InterruptedException {
// From https://github.com/ReactiveX/RxJava/pull/951
final Subscription s = mock(Subscription.class);
Flowable<String> never = Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(s);
}
});
TestScheduler testScheduler = new TestScheduler();
Flowable<String> observableWithTimeout = never.timeout(1000, TimeUnit.MILLISECONDS, testScheduler);
TestSubscriberEx<String> subscriber = new TestSubscriberEx<>();
observableWithTimeout.subscribe(subscriber);
testScheduler.advanceTimeBy(2000, TimeUnit.MILLISECONDS);
subscriber.assertFailureAndMessage(TimeoutException.class, timeoutMessage(1000, TimeUnit.MILLISECONDS));
verify(s, times(1)).cancel();
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableSkipTimedTest method skipTimedErrorAfterTime.
@Test
public void skipTimedErrorAfterTime() {
TestScheduler scheduler = new TestScheduler();
PublishProcessor<Integer> source = PublishProcessor.create();
Flowable<Integer> result = source.skip(1, TimeUnit.SECONDS, scheduler);
Subscriber<Object> subscriber = TestHelper.mockSubscriber();
result.subscribe(subscriber);
source.onNext(1);
source.onNext(2);
source.onNext(3);
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
source.onNext(4);
source.onNext(5);
source.onNext(6);
source.onError(new TestException());
InOrder inOrder = inOrder(subscriber);
inOrder.verify(subscriber, never()).onNext(1);
inOrder.verify(subscriber, never()).onNext(2);
inOrder.verify(subscriber, never()).onNext(3);
inOrder.verify(subscriber).onNext(4);
inOrder.verify(subscriber).onNext(5);
inOrder.verify(subscriber).onNext(6);
inOrder.verify(subscriber).onError(any(TestException.class));
inOrder.verifyNoMoreInteractions();
verify(subscriber, never()).onComplete();
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class SingleTimeoutTest method errorTimeoutRace.
@Test
public void errorTimeoutRace() {
final TestException ex = new TestException();
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
final SingleSubject<Integer> subj = SingleSubject.create();
SingleSubject<Integer> fallback = SingleSubject.create();
final TestScheduler sch = new TestScheduler();
TestObserver<Integer> to = subj.timeout(1, TimeUnit.MILLISECONDS, sch, fallback).test();
Runnable r1 = new Runnable() {
@Override
public void run() {
subj.onError(ex);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
sch.advanceTimeBy(1, TimeUnit.MILLISECONDS);
}
};
TestHelper.race(r1, r2);
if (!fallback.hasObservers()) {
to.assertFailure(TestException.class);
} else {
to.assertEmpty();
}
if (!errors.isEmpty()) {
TestHelper.assertUndeliverable(errors, 0, TestException.class);
}
}
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class SingleTimeoutTest method fallbackDispose.
@Test
public void fallbackDispose() {
TestScheduler sch = new TestScheduler();
SingleSubject<Integer> subj = SingleSubject.create();
SingleSubject<Integer> fallback = SingleSubject.create();
TestObserver<Integer> to = subj.timeout(1, TimeUnit.SECONDS, sch, fallback).test();
assertFalse(fallback.hasObservers());
sch.advanceTimeBy(1, TimeUnit.SECONDS);
assertFalse(subj.hasObservers());
assertTrue(fallback.hasObservers());
to.dispose();
assertFalse(fallback.hasObservers());
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class SingleTimeoutTest method disposeWhenFallback.
@Test
public void disposeWhenFallback() {
TestScheduler sch = new TestScheduler();
SingleSubject<Integer> subj = SingleSubject.create();
subj.timeout(1, TimeUnit.SECONDS, sch, Single.just(1)).test(true).assertEmpty();
assertFalse(subj.hasObservers());
}
Aggregations