From 507eba8c9d3ef672c46a3e819a913b65550bcdda Mon Sep 17 00:00:00 2001 From: jimi-21 Date: Mon, 16 Nov 2026 21:59:40 +0800 Subject: [PATCH 1/2] 4.x: Isolate Single flatMapIterable flowable race tests --- ...leFlatMapIterableFlowableIsolatedTest.java | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleFlatMapIterableFlowableIsolatedTest.java diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleFlatMapIterableFlowableIsolatedTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleFlatMapIterableFlowableIsolatedTest.java new file mode 100644 index 0000000000..e6ca5cb73f --- /dev/null +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleFlatMapIterableFlowableIsolatedTest.java @@ -0,0 +1,123 @@ +/* + * 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.*; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Isolated; + +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.subjects.*; +import io.reactivex.rxjava4.subscribers.TestSubscriber; +import io.reactivex.rxjava4.testsupport.TestHelper; + +@Isolated +public class SingleFlatMapIterableFlowableIsolatedTest extends RxJavaTest { + + @Test + public void requestCreateInnerRace() { + final Integer[] a = new Integer[1000]; + Arrays.fill(a, 1); + + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + final PublishSubject ps = PublishSubject.create(); + + ps.onNext(1); + + final TestSubscriber ts = ps.singleElement().flattenAsFlowable( + (Function>) _ -> Arrays.asList(a)) + .test(0L); + + Runnable r1 = () -> { + ps.onComplete(); + for (int i1 = 0; i1 < 500; i1++) { + ts.request(1); + } + }; + + Runnable r2 = () -> { + for (int i2 = 0; i2 < 500; i2++) { + ts.request(1); + } + }; + + TestHelper.race(r1, r2); + } + } + + @Test + public void cancelCreateInnerRace() { + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + final PublishSubject ps = PublishSubject.create(); + + ps.onNext(1); + + final TestSubscriber ts = ps.singleElement().flattenAsFlowable( + (Function>) _ -> Arrays.asList(1, 2, 3)) + .test(0L); + + Runnable r1 = ps::onComplete; + + Runnable r2 = ts::cancel; + + TestHelper.race(r1, r2); + } + } + + @Test + public void requestIteratorRace() { + final Integer[] a = new Integer[1000]; + Arrays.fill(a, 1); + + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + final PublishSubject ps = PublishSubject.create(); + + final TestSubscriber ts = ps.singleOrError().flattenAsFlowable((Function>) _ -> Arrays.asList(a)).test(); + + Runnable r1 = () -> { + for (int i1 = 0; i1 < 1000; i1++) { + ts.request(1); + } + }; + + Runnable r2 = () -> { + ps.onNext(1); + ps.onComplete(); + }; + + TestHelper.race(r1, r2); + } + } + + @Test + public void onSuccessRequestRace() { + List list = List.of(1); + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { + + SingleSubject ss = SingleSubject.create(); + + TestSubscriber ts = ss.flattenAsFlowable(_ -> list) + .test(0L); + + TestHelper.race( + () -> ss.onSuccess(1), + () -> ts.request(1) + ); + + ts.assertResult(1); + } + } +} From 47fbe8eb6fcae7a2316a789f8a00efcc11df4dc3 Mon Sep 17 00:00:00 2001 From: jimi-21 Date: Mon, 16 Nov 2026 21:59:42 +0800 Subject: [PATCH 2/2] 4.x: Isolate Single flatMapIterable flowable race tests --- .../SingleFlatMapIterableFlowableTest.java | 93 ------------------- 1 file changed, 93 deletions(-) diff --git a/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleFlatMapIterableFlowableTest.java b/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleFlatMapIterableFlowableTest.java index 3ce2df1a93..0c8fa65eb6 100644 --- a/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleFlatMapIterableFlowableTest.java +++ b/src/test/java/io/reactivex/rxjava4/internal/operators/single/SingleFlatMapIterableFlowableTest.java @@ -290,56 +290,6 @@ public void requestBefore() { } } - @Test - public void requestCreateInnerRace() { - final Integer[] a = new Integer[1000]; - Arrays.fill(a, 1); - - for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - final PublishSubject ps = PublishSubject.create(); - - ps.onNext(1); - - final TestSubscriber ts = ps.singleElement().flattenAsFlowable( - (Function>) _ -> Arrays.asList(a)) - .test(0L); - - Runnable r1 = () -> { - ps.onComplete(); - for (int i1 = 0; i1 < 500; i1++) { - ts.request(1); - } - }; - - Runnable r2 = () -> { - for (int i2 = 0; i2 < 500; i2++) { - ts.request(1); - } - }; - - TestHelper.race(r1, r2); - } - } - - @Test - public void cancelCreateInnerRace() { - for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - final PublishSubject ps = PublishSubject.create(); - - ps.onNext(1); - - final TestSubscriber ts = ps.singleElement().flattenAsFlowable( - (Function>) _ -> Arrays.asList(1, 2, 3)) - .test(0L); - - Runnable r1 = ps::onComplete; - - Runnable r2 = ts::cancel; - - TestHelper.race(r1, r2); - } - } - @Test public void slowPathCancelAfterHasNext() { final Integer[] a = new Integer[1000]; @@ -410,31 +360,6 @@ public void remove() { ts.assertValues(1, 1).assertNoErrors().assertNotComplete(); } - @Test - public void requestIteratorRace() { - final Integer[] a = new Integer[1000]; - Arrays.fill(a, 1); - - for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - final PublishSubject ps = PublishSubject.create(); - - final TestSubscriber ts = ps.singleOrError().flattenAsFlowable((Function>) _ -> Arrays.asList(a)).test(); - - Runnable r1 = () -> { - for (int i1 = 0; i1 < 1000; i1++) { - ts.request(1); - } - }; - - Runnable r2 = () -> { - ps.onNext(1); - ps.onComplete(); - }; - - TestHelper.race(r1, r2); - } - } - @Test public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeSingleToFlowable(s -> s.flattenAsFlowable(_ -> Collections.emptyList())); @@ -463,22 +388,4 @@ public void onNext(@NonNull Integer t) { ts.assertResult(1); } - @Test - public void onSuccessRequestRace() { - List list = List.of(1); - for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - - SingleSubject ss = SingleSubject.create(); - - TestSubscriber ts = ss.flattenAsFlowable(_ -> list) - .test(0L); - - TestHelper.race( - () -> ss.onSuccess(1), - () -> ts.request(1) - ); - - ts.assertResult(1); - } - } }