diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleAmbIsolatedTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleAmbIsolatedTest.java new file mode 100644 index 0000000000..4413e9679c --- /dev/null +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleAmbIsolatedTest.java @@ -0,0 +1,120 @@ +/* + * 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.single; + +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Isolated; + +import io.reactivex.rxjava4.core.RxJavaTest; +import io.reactivex.rxjava4.core.Single; +import io.reactivex.rxjava4.exceptions.TestException; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.subjects.PublishSubject; +import io.reactivex.rxjava4.subjects.ReplaySubject; +import io.reactivex.rxjava4.subjects.Subject; +import io.reactivex.rxjava4.testsupport.TestHelper; + +@Isolated +public class SingleAmbIsolatedTest extends RxJavaTest { + + @Test + public void nullSourceSuccessRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + List errors = TestHelper.trackPluginErrors(); + + try { + + final Subject ps = ReplaySubject.create(); + ps.onNext(1); + + final Single source = Single.ambArray(ps.singleOrError(), Single.never(), Single.never(), null); + + Runnable r1 = source::test; + + Runnable r2 = ps::onComplete; + + TestHelper.race(r1, r2); + + if (!errors.isEmpty()) { + TestHelper.assertError(errors, 0, NullPointerException.class); + } + } finally { + RxJavaPlugins.reset(); + } + } + } + + @Test + public void multipleErrorRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + List errors = TestHelper.trackPluginErrors(); + + try { + + final Subject ps1 = PublishSubject.create(); + final Subject ps2 = PublishSubject.create(); + + Single.ambArray(ps1.singleOrError(), ps2.singleOrError()).test(); + + final TestException ex = new TestException(); + + Runnable r1 = () -> ps1.onError(ex); + + Runnable r2 = () -> ps2.onError(ex); + + TestHelper.race(r1, r2); + + if (!errors.isEmpty()) { + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } + } finally { + RxJavaPlugins.reset(); + } + } + } + + @Test + public void successErrorRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + List errors = TestHelper.trackPluginErrors(); + + try { + + final Subject ps1 = PublishSubject.create(); + final Subject ps2 = PublishSubject.create(); + + Single.ambArray(ps1.singleOrError(), ps2.singleOrError()).test(); + + final TestException ex = new TestException(); + + Runnable r1 = () -> { + ps1.onNext(1); + ps1.onComplete(); + }; + + Runnable r2 = () -> ps2.onError(ex); + + TestHelper.race(r1, r2); + + if (!errors.isEmpty()) { + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } + } finally { + RxJavaPlugins.reset(); + } + } + } +} diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleAmbTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleAmbTest.java index cca0aabcbb..46bf5bdc1d 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleAmbTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleAmbTest.java @@ -25,7 +25,6 @@ import io.reactivex.rxjava4.exceptions.TestException; import io.reactivex.rxjava4.functions.BiConsumer; import io.reactivex.rxjava4.observers.TestObserver; -import io.reactivex.rxjava4.plugins.RxJavaPlugins; import io.reactivex.rxjava4.processors.PublishProcessor; import io.reactivex.rxjava4.schedulers.Schedulers; import io.reactivex.rxjava4.subjects.*; @@ -131,94 +130,6 @@ public void error() { .assertFailure(TestException.class); } - @Test - public void nullSourceSuccessRace() { - for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - List errors = TestHelper.trackPluginErrors(); - - try { - - final Subject ps = ReplaySubject.create(); - ps.onNext(1); - - final Single source = Single.ambArray(ps.singleOrError(), Single.never(), Single.never(), null); - - Runnable r1 = source::test; - - Runnable r2 = ps::onComplete; - - TestHelper.race(r1, r2); - - if (!errors.isEmpty()) { - TestHelper.assertError(errors, 0, NullPointerException.class); - } - } finally { - RxJavaPlugins.reset(); - } - } - } - - @Test - public void multipleErrorRace() { - for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - List errors = TestHelper.trackPluginErrors(); - - try { - - final Subject ps1 = PublishSubject.create(); - final Subject ps2 = PublishSubject.create(); - - Single.ambArray(ps1.singleOrError(), ps2.singleOrError()).test(); - - final TestException ex = new TestException(); - - Runnable r1 = () -> ps1.onError(ex); - - Runnable r2 = () -> ps2.onError(ex); - - TestHelper.race(r1, r2); - - if (!errors.isEmpty()) { - TestHelper.assertUndeliverable(errors, 0, TestException.class); - } - } finally { - RxJavaPlugins.reset(); - } - } - } - - @Test - public void successErrorRace() { - for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - List errors = TestHelper.trackPluginErrors(); - - try { - - final Subject ps1 = PublishSubject.create(); - final Subject ps2 = PublishSubject.create(); - - Single.ambArray(ps1.singleOrError(), ps2.singleOrError()).test(); - - final TestException ex = new TestException(); - - Runnable r1 = () -> { - ps1.onNext(1); - ps1.onComplete(); - }; - - Runnable r2 = () -> ps2.onError(ex); - - TestHelper.race(r1, r2); - - if (!errors.isEmpty()) { - TestHelper.assertUndeliverable(errors, 0, TestException.class); - } - } finally { - RxJavaPlugins.reset(); - } - } - } - @Test public void manySources() { @SuppressWarnings("unchecked") diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleUsingIsolatedTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleUsingIsolatedTest.java new file mode 100644 index 0000000000..ab82b7d4d9 --- /dev/null +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleUsingIsolatedTest.java @@ -0,0 +1,81 @@ +/* + * 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.single; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Isolated; + +import io.reactivex.rxjava4.core.RxJavaTest; +import io.reactivex.rxjava4.core.Single; +import io.reactivex.rxjava4.core.SingleSource; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.TestException; +import io.reactivex.rxjava4.functions.Consumer; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.internal.functions.Functions; +import io.reactivex.rxjava4.observers.TestObserver; +import io.reactivex.rxjava4.processors.PublishProcessor; +import io.reactivex.rxjava4.testsupport.SuppressUndeliverable; +import io.reactivex.rxjava4.testsupport.TestHelper; + +@Isolated +public class SingleUsingIsolatedTest extends RxJavaTest { + + final Consumer disposer = Disposable::dispose; + + @Test + public void successDisposeRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + final PublishProcessor pp = PublishProcessor.create(); + + Disposable d = Disposable.empty(); + + final TestObserver to = Single.using(Functions.justSupplier(d), (Function>) _ -> pp.single(-99), disposer) + .test(); + + pp.onNext(1); + + Runnable r1 = pp::onComplete; + Runnable r2 = to::dispose; + + TestHelper.race(r1, r2); + + assertTrue(d.isDisposed()); + } + } + + @Test + @SuppressUndeliverable + public void errorDisposeRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + final PublishProcessor pp = PublishProcessor.create(); + + Disposable d = Disposable.empty(); + + final TestObserver to = Single.using(Functions.justSupplier(d), (Function>) _ -> pp.single(-99), disposer) + .test(); + + final TestException ex = new TestException(); + + Runnable r1 = () -> pp.onError(ex); + Runnable r2 = to::dispose; + + TestHelper.race(r1, r2); + + assertTrue(d.isDisposed()); + } + } +} diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleUsingTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleUsingTest.java index a4464d8f52..6939d8cc61 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleUsingTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleUsingTest.java @@ -188,27 +188,6 @@ public void errorAndDisposerThrowsNonEager() { } } - @Test - public void successDisposeRace() { - for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - final PublishProcessor pp = PublishProcessor.create(); - - Disposable d = Disposable.empty(); - - final TestObserver to = Single.using(Functions.justSupplier(d), (Function>) _ -> pp.single(-99), disposer) - .test(); - - pp.onNext(1); - - Runnable r1 = pp::onComplete; - Runnable r2 = to::dispose; - - TestHelper.race(r1, r2); - - assertTrue(d.isDisposed()); - } - } - @Test public void doubleOnSubscribe() { List errors = TestHelper.trackPluginErrors(); @@ -243,28 +222,6 @@ protected void subscribeActual(SingleObserver observer) { } } - @Test - @SuppressUndeliverable - public void errorDisposeRace() { - for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - final PublishProcessor pp = PublishProcessor.create(); - - Disposable d = Disposable.empty(); - - final TestObserver to = Single.using(Functions.justSupplier(d), (Function>) _ -> pp.single(-99), disposer) - .test(); - - final TestException ex = new TestException(); - - Runnable r1 = () -> pp.onError(ex); - Runnable r2 = to::dispose; - - TestHelper.race(r1, r2); - - assertTrue(d.isDisposed()); - } - } - @Test public void eagerDisposeResourceThenDisposeUpstream() { final StringBuilder sb = new StringBuilder();