diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/completable/CompletableTimeoutIsolatedTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/completable/CompletableTimeoutIsolatedTest.java new file mode 100644 index 0000000000..4f5a3067f1 --- /dev/null +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/completable/CompletableTimeoutIsolatedTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package io.reactivex.rxjava4.internal.operators.completable; + +import java.util.List; +import java.util.concurrent.TimeUnit; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Isolated; + +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.TestException; +import io.reactivex.rxjava4.testsupport.TestObserverEx; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.schedulers.TestScheduler; +import io.reactivex.rxjava4.subjects.PublishSubject; +import io.reactivex.rxjava4.testsupport.TestHelper; + +@Isolated +public class CompletableTimeoutIsolatedTest extends RxJavaTest { + + @Test + public void errorTimeoutRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + List errors = TestHelper.trackPluginErrors(); + + try { + final TestScheduler scheduler = new TestScheduler(); + + final PublishSubject ps = PublishSubject.create(); + + TestObserverEx to = ps.ignoreElements() + .timeout(1, TimeUnit.MILLISECONDS, scheduler, Completable.complete()) + .to(TestHelper.testConsumer()); + + final TestException ex = new TestException(); + + Runnable r1 = () -> ps.onError(ex); + + Runnable r2 = () -> scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS); + + TestHelper.race(r1, r2); + + to.assertTerminated(); + + if (!errors.isEmpty()) { + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } + + } finally { + RxJavaPlugins.reset(); + } + } + } +} diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/completable/CompletableTimeoutTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/completable/CompletableTimeoutTest.java index 13c3830325..ba4abdd2b3 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/completable/CompletableTimeoutTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/completable/CompletableTimeoutTest.java @@ -103,40 +103,6 @@ public void mainError() { .assertFailure(TestException.class); } - @Test - public void errorTimeoutRace() { - for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - List errors = TestHelper.trackPluginErrors(); - - try { - final TestScheduler scheduler = new TestScheduler(); - - final PublishSubject ps = PublishSubject.create(); - - TestObserverEx to = ps.ignoreElements() - .timeout(1, TimeUnit.MILLISECONDS, scheduler, Completable.complete()) - .to(TestHelper.testConsumer()); - - final TestException ex = new TestException(); - - Runnable r1 = () -> ps.onError(ex); - - Runnable r2 = () -> scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS); - - TestHelper.race(r1, r2); - - to.assertTerminated(); - - if (!errors.isEmpty()) { - TestHelper.assertUndeliverable(errors, 0, TestException.class); - } - - } finally { - RxJavaPlugins.reset(); - } - } - } - @Test public void ambRace() { TestObserver to = new TestObserver<>(); diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/completable/CompletableUsingIsolatedTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/completable/CompletableUsingIsolatedTest.java new file mode 100644 index 0000000000..dacd32ba24 --- /dev/null +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/completable/CompletableUsingIsolatedTest.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package io.reactivex.rxjava4.internal.operators.completable; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Isolated; + +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.TestException; +import io.reactivex.rxjava4.internal.functions.Functions; +import io.reactivex.rxjava4.observers.TestObserver; +import io.reactivex.rxjava4.testsupport.TestObserverEx; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.subjects.PublishSubject; +import io.reactivex.rxjava4.testsupport.TestHelper; + +@Isolated +public class CompletableUsingIsolatedTest extends RxJavaTest { + + @Test + public void successDisposeRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + + final PublishSubject ps = PublishSubject.create(); + + final TestObserverEx to = Completable.using(() -> 1, _ -> ps.ignoreElements(), + _ -> { }, true) + .to(TestHelper.testConsumer()); + + ps.onNext(1); + + Runnable r1 = to::dispose; + + Runnable r2 = ps::onComplete; + + TestHelper.race(r1, r2); + } + } + + @Test + public void errorDisposeRace() { + RxJavaPlugins.setErrorHandler(Functions.emptyConsumer()); + try { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + + final PublishSubject ps = PublishSubject.create(); + + final TestObserver to = Completable.using(() -> 1, _ -> ps.ignoreElements(), + _ -> { }, true) + .test(); + + final TestException ex = new TestException(); + + Runnable r1 = to::dispose; + + Runnable r2 = () -> ps.onError(ex); + + TestHelper.race(r1, r2); + } + } finally { + RxJavaPlugins.reset(); + } + } + + @Test + public void emptyDisposeRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + + final PublishSubject ps = PublishSubject.create(); + + final TestObserver to = Completable.using(() -> 1, _ -> ps.ignoreElements(), + _ -> { }, true) + .test(); + + Runnable r1 = to::dispose; + + Runnable r2 = ps::onComplete; + + TestHelper.race(r1, r2); + } + } +} diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/completable/CompletableUsingTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/completable/CompletableUsingTest.java index ea4b1f1f6d..a45fe4ee4f 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/completable/CompletableUsingTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/completable/CompletableUsingTest.java @@ -225,69 +225,6 @@ public void doubleOnSubscribe() { } } - @Test - public void successDisposeRace() { - for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - - final PublishSubject ps = PublishSubject.create(); - - final TestObserverEx to = Completable.using(() -> 1, _ -> ps.ignoreElements(), - _ -> { }, true) - .to(TestHelper.testConsumer()); - - ps.onNext(1); - - Runnable r1 = to::dispose; - - Runnable r2 = ps::onComplete; - - TestHelper.race(r1, r2); - } - } - - @Test - public void errorDisposeRace() { - RxJavaPlugins.setErrorHandler(Functions.emptyConsumer()); - try { - for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - - final PublishSubject ps = PublishSubject.create(); - - final TestObserver to = Completable.using(() -> 1, _ -> ps.ignoreElements(), - _ -> { }, true) - .test(); - - final TestException ex = new TestException(); - - Runnable r1 = to::dispose; - - Runnable r2 = () -> ps.onError(ex); - - TestHelper.race(r1, r2); - } - } finally { - RxJavaPlugins.reset(); - } - } - - @Test - public void emptyDisposeRace() { - for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - - final PublishSubject ps = PublishSubject.create(); - - final TestObserver to = Completable.using(() -> 1, _ -> ps.ignoreElements(), - _ -> { }, true) - .test(); - - Runnable r1 = to::dispose; - - Runnable r2 = ps::onComplete; - - TestHelper.race(r1, r2); - } - } - @Test public void eagerDisposeResourceThenDisposeUpstream() { final StringBuilder sb = new StringBuilder();