From fd2005e842538f209f50357ad647540a55a391fc Mon Sep 17 00:00:00 2001 From: JimmyLiuJia <91264074+JimmyLiuJia@users.noreply.github.com> Date: Sun, 11 Oct 2026 21:30:44 +0800 Subject: [PATCH] test: isolate Maybe zip race tests (Related #8075) --- .../maybe/MaybeZipArrayIsolatedTest.java | 64 ++++++++++++++++++ .../operators/maybe/MaybeZipArrayTest.java | 31 --------- .../maybe/MaybeZipIterableIsolatedTest.java | 66 +++++++++++++++++++ .../operators/maybe/MaybeZipIterableTest.java | 32 --------- 4 files changed, 130 insertions(+), 63 deletions(-) create mode 100644 src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeZipArrayIsolatedTest.java create mode 100644 src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeZipIterableIsolatedTest.java diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeZipArrayIsolatedTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeZipArrayIsolatedTest.java new file mode 100644 index 0000000000..634f6aaeab --- /dev/null +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeZipArrayIsolatedTest.java @@ -0,0 +1,64 @@ +/* + * 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.maybe; + +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Isolated; + +import io.reactivex.rxjava4.core.Maybe; +import io.reactivex.rxjava4.core.RxJavaTest; +import io.reactivex.rxjava4.exceptions.TestException; +import io.reactivex.rxjava4.functions.BiFunction; +import io.reactivex.rxjava4.observers.TestObserver; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.processors.PublishProcessor; +import io.reactivex.rxjava4.testsupport.TestHelper; + +@Isolated +public class MaybeZipArrayIsolatedTest extends RxJavaTest { + + final BiFunction addString = (a, b) -> "" + a + b; + + @Test + public void innerErrorRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + List errors = TestHelper.trackPluginErrors(); + try { + final PublishProcessor pp0 = PublishProcessor.create(); + final PublishProcessor pp1 = PublishProcessor.create(); + + final TestObserver to = Maybe.zip(pp0.singleElement(), pp1.singleElement(), addString) + .test(); + + final TestException ex = new TestException(); + + Runnable r1 = () -> pp0.onError(ex); + + Runnable r2 = () -> pp1.onError(ex); + + TestHelper.race(r1, r2); + + to.assertFailure(TestException.class); + + if (!errors.isEmpty()) { + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } + } finally { + RxJavaPlugins.reset(); + } + } + } +} diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeZipArrayTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeZipArrayTest.java index 2079c1b0a2..b3f27d375e 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeZipArrayTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeZipArrayTest.java @@ -27,7 +27,6 @@ import io.reactivex.rxjava4.functions.*; import io.reactivex.rxjava4.internal.functions.Functions; import io.reactivex.rxjava4.observers.TestObserver; -import io.reactivex.rxjava4.plugins.RxJavaPlugins; import io.reactivex.rxjava4.processors.PublishProcessor; import io.reactivex.rxjava4.subjects.MaybeSubject; import io.reactivex.rxjava4.testsupport.TestHelper; @@ -97,36 +96,6 @@ public void middleError() { to.assertFailure(TestException.class); } - @Test - public void innerErrorRace() { - for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - List errors = TestHelper.trackPluginErrors(); - try { - final PublishProcessor pp0 = PublishProcessor.create(); - final PublishProcessor pp1 = PublishProcessor.create(); - - final TestObserver to = Maybe.zip(pp0.singleElement(), pp1.singleElement(), addString) - .test(); - - final TestException ex = new TestException(); - - Runnable r1 = () -> pp0.onError(ex); - - Runnable r2 = () -> pp1.onError(ex); - - TestHelper.race(r1, r2); - - to.assertFailure(TestException.class); - - if (!errors.isEmpty()) { - TestHelper.assertUndeliverable(errors, 0, TestException.class); - } - } finally { - RxJavaPlugins.reset(); - } - } - } - @Test public void zipArrayOneIsNull() { assertThrows(NullPointerException.class, () -> { diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeZipIterableIsolatedTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeZipIterableIsolatedTest.java new file mode 100644 index 0000000000..06670ada81 --- /dev/null +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeZipIterableIsolatedTest.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.maybe; + +import java.util.Arrays; +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Isolated; + +import io.reactivex.rxjava4.core.Maybe; +import io.reactivex.rxjava4.core.RxJavaTest; +import io.reactivex.rxjava4.exceptions.TestException; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.observers.TestObserver; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.processors.PublishProcessor; +import io.reactivex.rxjava4.testsupport.TestHelper; + +@Isolated +public class MaybeZipIterableIsolatedTest extends RxJavaTest { + + final Function addString = Arrays::toString; + + @Test + public void innerErrorRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + List errors = TestHelper.trackPluginErrors(); + try { + final PublishProcessor pp0 = PublishProcessor.create(); + final PublishProcessor pp1 = PublishProcessor.create(); + + final TestObserver to = Maybe.zip( + Arrays.asList(pp0.singleElement(), pp1.singleElement()), addString) + .test(); + + final TestException ex = new TestException(); + + Runnable r1 = () -> pp0.onError(ex); + + Runnable r2 = () -> pp1.onError(ex); + + TestHelper.race(r1, r2); + + to.assertFailure(TestException.class); + + if (!errors.isEmpty()) { + TestHelper.assertUndeliverable(errors, 0, TestException.class); + } + } finally { + RxJavaPlugins.reset(); + } + } + } +} diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeZipIterableTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeZipIterableTest.java index 8e4df23ae4..d06f667a6a 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeZipIterableTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeZipIterableTest.java @@ -25,7 +25,6 @@ import io.reactivex.rxjava4.internal.functions.Functions; import io.reactivex.rxjava4.internal.util.CrashingMappedIterable; import io.reactivex.rxjava4.observers.TestObserver; -import io.reactivex.rxjava4.plugins.RxJavaPlugins; import io.reactivex.rxjava4.processors.PublishProcessor; import io.reactivex.rxjava4.testsupport.TestHelper; @@ -93,37 +92,6 @@ public void middleError() { to.assertFailure(TestException.class); } - @Test - public void innerErrorRace() { - for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - List errors = TestHelper.trackPluginErrors(); - try { - final PublishProcessor pp0 = PublishProcessor.create(); - final PublishProcessor pp1 = PublishProcessor.create(); - - final TestObserver to = Maybe.zip( - Arrays.asList(pp0.singleElement(), pp1.singleElement()), addString) - .test(); - - final TestException ex = new TestException(); - - Runnable r1 = () -> pp0.onError(ex); - - Runnable r2 = () -> pp1.onError(ex); - - TestHelper.race(r1, r2); - - to.assertFailure(TestException.class); - - if (!errors.isEmpty()) { - TestHelper.assertUndeliverable(errors, 0, TestException.class); - } - } finally { - RxJavaPlugins.reset(); - } - } - } - @Test public void iteratorThrows() { Maybe.zip(new CrashingMappedIterable<>(1, 100, 100, Maybe::just), addString)