From 04b9c7879627abbb13de449407e95347ce0b08b8 Mon Sep 17 00:00:00 2001 From: jimi-21 Date: Tue, 17 Nov 2026 16:53:12 +0800 Subject: [PATCH] 4.x: Isolate DeferredScalarSubscription race tests --- ...eferredScalarSubscriptionIsolatedTest.java | 80 +++++++++++++++++++ .../DeferredScalarSubscriptionTest.java | 54 ------------- 2 files changed, 80 insertions(+), 54 deletions(-) create mode 100644 src/test/java/io/reactivex/rxjava4/internal/subscriptions/DeferredScalarSubscriptionIsolatedTest.java diff --git a/src/test/java/io/reactivex/rxjava4/internal/subscriptions/DeferredScalarSubscriptionIsolatedTest.java b/src/test/java/io/reactivex/rxjava4/internal/subscriptions/DeferredScalarSubscriptionIsolatedTest.java new file mode 100644 index 0000000000..9a120017f5 --- /dev/null +++ b/src/test/java/io/reactivex/rxjava4/internal/subscriptions/DeferredScalarSubscriptionIsolatedTest.java @@ -0,0 +1,80 @@ +/* + * 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.subscriptions; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Isolated; + +import io.reactivex.rxjava4.core.RxJavaTest; +import io.reactivex.rxjava4.subscribers.TestSubscriber; +import io.reactivex.rxjava4.testsupport.TestHelper; + +@Isolated +public class DeferredScalarSubscriptionIsolatedTest extends RxJavaTest { + + @Test + public void completeCancelRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + final DeferredScalarSubscription ds = new DeferredScalarSubscription<>(new TestSubscriber<>()); + + Runnable r1 = () -> ds.complete(1); + + Runnable r2 = ds::cancel; + + TestHelper.race(r1, r2); + } + } + + @Test + public void requestClearRace() { + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + TestSubscriber ts = new TestSubscriber<>(0L); + + final DeferredScalarSubscription ds = new DeferredScalarSubscription<>(ts); + ts.onSubscribe(ds); + ds.complete(1); + + Runnable r1 = () -> ds.request(1); + + Runnable r2 = () -> ds.value = null; + + TestHelper.race(r1, r2); + + if (!ts.values().isEmpty()) { + ts.assertValue(1); + } + } + } + + @Test + public void requestCancelRace() { + for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { + TestSubscriber ts = new TestSubscriber<>(0L); + + final DeferredScalarSubscription ds = new DeferredScalarSubscription<>(ts); + ts.onSubscribe(ds); + ds.complete(1); + + Runnable r1 = () -> ds.request(1); + + Runnable r2 = ds::cancel; + + TestHelper.race(r1, r2); + + if (!ts.values().isEmpty()) { + ts.assertValue(1); + } + } + } +} diff --git a/src/test/java/io/reactivex/rxjava4/internal/subscriptions/DeferredScalarSubscriptionTest.java b/src/test/java/io/reactivex/rxjava4/internal/subscriptions/DeferredScalarSubscriptionTest.java index 9c961d1551..1705c4ff27 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/subscriptions/DeferredScalarSubscriptionTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/subscriptions/DeferredScalarSubscriptionTest.java @@ -52,58 +52,4 @@ public void cancel() { assertFalse(ds.tryCancel()); } - @Test - public void completeCancelRace() { - for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - final DeferredScalarSubscription ds = new DeferredScalarSubscription<>(new TestSubscriber<>()); - - Runnable r1 = () -> ds.complete(1); - - Runnable r2 = ds::cancel; - - TestHelper.race(r1, r2); - } - } - - @Test - public void requestClearRace() { - for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { - TestSubscriber ts = new TestSubscriber<>(0L); - - final DeferredScalarSubscription ds = new DeferredScalarSubscription<>(ts); - ts.onSubscribe(ds); - ds.complete(1); - - Runnable r1 = () -> ds.request(1); - - Runnable r2 = () -> ds.value = null; - - TestHelper.race(r1, r2); - - if (!ts.values().isEmpty()) { - ts.assertValue(1); - } - } - } - - @Test - public void requestCancelRace() { - for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { - TestSubscriber ts = new TestSubscriber<>(0L); - - final DeferredScalarSubscription ds = new DeferredScalarSubscription<>(ts); - ts.onSubscribe(ds); - ds.complete(1); - - Runnable r1 = () -> ds.request(1); - - Runnable r2 = ds::cancel; - - TestHelper.race(r1, r2); - - if (!ts.values().isEmpty()) { - ts.assertValue(1); - } - } - } }