Skip to content

Commit 884e27d

Browse files
authored
4.x: Isolate FutureSubscriber race tests (#8393)
1 parent 77d4ee3 commit 884e27d

2 files changed

Lines changed: 76 additions & 49 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) 2016-present, RxJava Contributors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5+
* compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is
10+
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11+
* the License for the specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package io.reactivex.rxjava4.internal.subscribers;
15+
16+
import org.junit.jupiter.api.Test;
17+
import org.junit.jupiter.api.parallel.Isolated;
18+
19+
import io.reactivex.rxjava4.core.RxJavaTest;
20+
import io.reactivex.rxjava4.exceptions.TestException;
21+
import io.reactivex.rxjava4.internal.subscriptions.BooleanSubscription;
22+
import io.reactivex.rxjava4.testsupport.SuppressUndeliverable;
23+
import io.reactivex.rxjava4.testsupport.TestHelper;
24+
25+
@Isolated
26+
public class FutureSubscriberIsolatedTest extends RxJavaTest {
27+
28+
@Test
29+
public void cancelRace() {
30+
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
31+
final FutureSubscriber<Integer> fs = new FutureSubscriber<>();
32+
33+
Runnable r = () -> fs.cancel(false);
34+
35+
TestHelper.race(r, r);
36+
}
37+
}
38+
39+
@Test
40+
@SuppressUndeliverable
41+
public void onErrorCancelRace() {
42+
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
43+
final FutureSubscriber<Integer> fs = new FutureSubscriber<>();
44+
45+
final TestException ex = new TestException();
46+
47+
Runnable r1 = () -> fs.cancel(false);
48+
49+
Runnable r2 = () -> fs.onError(ex);
50+
51+
TestHelper.race(r1, r2);
52+
}
53+
}
54+
55+
@Test
56+
@SuppressUndeliverable
57+
public void onCompleteCancelRace() {
58+
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
59+
final FutureSubscriber<Integer> fs = new FutureSubscriber<>();
60+
61+
if (i % 3 == 0) {
62+
fs.onSubscribe(new BooleanSubscription());
63+
}
64+
65+
if (i % 2 == 0) {
66+
fs.onNext(1);
67+
}
68+
69+
Runnable r1 = () -> fs.cancel(false);
70+
71+
Runnable r2 = fs::onComplete;
72+
73+
TestHelper.race(r1, r2);
74+
}
75+
}
76+
}

‎src/test/java/io/reactivex/rxjava4/internal/subscribers/FutureSubscriberTest.java‎

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,6 @@ public void onSubscribe() throws Exception {
125125
}
126126
}
127127

128-
@Test
129-
public void cancelRace() {
130-
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
131-
final FutureSubscriber<Integer> fs = new FutureSubscriber<>();
132-
133-
Runnable r = () -> fs.cancel(false);
134-
135-
TestHelper.race(r, r);
136-
}
137-
}
138-
139128
@Test
140129
public void await() throws Exception {
141130
Schedulers.single().scheduleDirect(() -> {
@@ -146,44 +135,6 @@ public void await() throws Exception {
146135
assertEquals(1, fs.get(5, TimeUnit.SECONDS).intValue());
147136
}
148137

149-
@Test
150-
@SuppressUndeliverable
151-
public void onErrorCancelRace() {
152-
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
153-
final FutureSubscriber<Integer> fs = new FutureSubscriber<>();
154-
155-
final TestException ex = new TestException();
156-
157-
Runnable r1 = () -> fs.cancel(false);
158-
159-
Runnable r2 = () -> fs.onError(ex);
160-
161-
TestHelper.race(r1, r2);
162-
}
163-
}
164-
165-
@Test
166-
@SuppressUndeliverable
167-
public void onCompleteCancelRace() {
168-
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
169-
final FutureSubscriber<Integer> fs = new FutureSubscriber<>();
170-
171-
if (i % 3 == 0) {
172-
fs.onSubscribe(new BooleanSubscription());
173-
}
174-
175-
if (i % 2 == 0) {
176-
fs.onNext(1);
177-
}
178-
179-
Runnable r1 = () -> fs.cancel(false);
180-
181-
Runnable r2 = fs::onComplete;
182-
183-
TestHelper.race(r1, r2);
184-
}
185-
}
186-
187138
@Test
188139
@SuppressUndeliverable
189140
public void onErrorOnComplete() throws Exception {

0 commit comments

Comments
 (0)