From ba32990ddce8e5e37e751b27b449d92c80a729c6 Mon Sep 17 00:00:00 2001 From: Jimmy Liu Jia <91264074+JimmyLiuJia@users.noreply.github.com> Date: Tue, 13 Oct 2026 15:08:50 +0800 Subject: [PATCH] 4.x: Isolate Maybe switchIfEmpty race tests --- .../maybe/MaybeSwitchIfEmptyIsolatedTest.java | 42 +++++++++++++++++++ .../MaybeSwitchIfEmptySingleIsolatedTest.java | 42 +++++++++++++++++++ .../maybe/MaybeSwitchIfEmptySingleTest.java | 15 ------- .../maybe/MaybeSwitchIfEmptyTest.java | 15 ------- 4 files changed, 84 insertions(+), 30 deletions(-) create mode 100644 src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeSwitchIfEmptyIsolatedTest.java create mode 100644 src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeSwitchIfEmptySingleIsolatedTest.java diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeSwitchIfEmptyIsolatedTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeSwitchIfEmptyIsolatedTest.java new file mode 100644 index 0000000000..8f417cff11 --- /dev/null +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeSwitchIfEmptyIsolatedTest.java @@ -0,0 +1,42 @@ +/* + * 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 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.observers.TestObserver; +import io.reactivex.rxjava4.processors.PublishProcessor; +import io.reactivex.rxjava4.testsupport.TestHelper; + +@Isolated +public class MaybeSwitchIfEmptyIsolatedTest extends RxJavaTest { + + @Test + public void emptyCancelRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + final PublishProcessor pp = PublishProcessor.create(); + + final TestObserver to = pp.singleElement().switchIfEmpty(Maybe.just(2)).test(); + + Runnable r1 = pp::onComplete; + + Runnable r2 = to::dispose; + + TestHelper.race(r1, r2); + } + } +} diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeSwitchIfEmptySingleIsolatedTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeSwitchIfEmptySingleIsolatedTest.java new file mode 100644 index 0000000000..42fe040910 --- /dev/null +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeSwitchIfEmptySingleIsolatedTest.java @@ -0,0 +1,42 @@ +/* + * 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 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.observers.TestObserver; +import io.reactivex.rxjava4.processors.PublishProcessor; +import io.reactivex.rxjava4.testsupport.TestHelper; + +@Isolated +public class MaybeSwitchIfEmptySingleIsolatedTest extends RxJavaTest { + + @Test + public void emptyCancelRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + final PublishProcessor pp = PublishProcessor.create(); + + final TestObserver to = pp.singleElement().switchIfEmpty(Single.just(2)).test(); + + Runnable r1 = pp::onComplete; + + Runnable r2 = to::dispose; + + TestHelper.race(r1, r2); + } + } +} diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeSwitchIfEmptySingleTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeSwitchIfEmptySingleTest.java index 44e3765430..9ab972681a 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeSwitchIfEmptySingleTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeSwitchIfEmptySingleTest.java @@ -74,21 +74,6 @@ public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeMaybeToSingle((Function, Single>) f -> f.switchIfEmpty(Single.just(2))); } - @Test - public void emptyCancelRace() { - for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - final PublishProcessor pp = PublishProcessor.create(); - - final TestObserver to = pp.singleElement().switchIfEmpty(Single.just(2)).test(); - - Runnable r1 = pp::onComplete; - - Runnable r2 = to::dispose; - - TestHelper.race(r1, r2); - } - } - @SuppressWarnings("rawtypes") @Test public void source() { diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeSwitchIfEmptyTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeSwitchIfEmptyTest.java index 1bc97c87fc..d899bb26a0 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeSwitchIfEmptyTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/maybe/MaybeSwitchIfEmptyTest.java @@ -88,19 +88,4 @@ public void isDisposed() { public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeMaybe((Function, Maybe>) f -> f.switchIfEmpty(Maybe.just(2))); } - - @Test - public void emptyCancelRace() { - for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - final PublishProcessor pp = PublishProcessor.create(); - - final TestObserver to = pp.singleElement().switchIfEmpty(Maybe.just(2)).test(); - - Runnable r1 = pp::onComplete; - - Runnable r2 = to::dispose; - - TestHelper.race(r1, r2); - } - } }