Skip to content

Commit e1346fe

Browse files
authored
4.x: Isolate DeferredScalarSubscription race tests (#8390)
1 parent 1bc6885 commit e1346fe

2 files changed

Lines changed: 80 additions & 54 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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.subscriptions;
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.subscribers.TestSubscriber;
21+
import io.reactivex.rxjava4.testsupport.TestHelper;
22+
23+
@Isolated
24+
public class DeferredScalarSubscriptionIsolatedTest extends RxJavaTest {
25+
26+
@Test
27+
public void completeCancelRace() {
28+
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
29+
final DeferredScalarSubscription<Integer> ds = new DeferredScalarSubscription<>(new TestSubscriber<>());
30+
31+
Runnable r1 = () -> ds.complete(1);
32+
33+
Runnable r2 = ds::cancel;
34+
35+
TestHelper.race(r1, r2);
36+
}
37+
}
38+
39+
@Test
40+
public void requestClearRace() {
41+
for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) {
42+
TestSubscriber<Integer> ts = new TestSubscriber<>(0L);
43+
44+
final DeferredScalarSubscription<Integer> ds = new DeferredScalarSubscription<>(ts);
45+
ts.onSubscribe(ds);
46+
ds.complete(1);
47+
48+
Runnable r1 = () -> ds.request(1);
49+
50+
Runnable r2 = () -> ds.value = null;
51+
52+
TestHelper.race(r1, r2);
53+
54+
if (!ts.values().isEmpty()) {
55+
ts.assertValue(1);
56+
}
57+
}
58+
}
59+
60+
@Test
61+
public void requestCancelRace() {
62+
for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) {
63+
TestSubscriber<Integer> ts = new TestSubscriber<>(0L);
64+
65+
final DeferredScalarSubscription<Integer> ds = new DeferredScalarSubscription<>(ts);
66+
ts.onSubscribe(ds);
67+
ds.complete(1);
68+
69+
Runnable r1 = () -> ds.request(1);
70+
71+
Runnable r2 = ds::cancel;
72+
73+
TestHelper.race(r1, r2);
74+
75+
if (!ts.values().isEmpty()) {
76+
ts.assertValue(1);
77+
}
78+
}
79+
}
80+
}

‎src/test/java/io/reactivex/rxjava4/internal/subscriptions/DeferredScalarSubscriptionTest.java‎

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -52,58 +52,4 @@ public void cancel() {
5252
assertFalse(ds.tryCancel());
5353
}
5454

55-
@Test
56-
public void completeCancelRace() {
57-
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
58-
final DeferredScalarSubscription<Integer> ds = new DeferredScalarSubscription<>(new TestSubscriber<>());
59-
60-
Runnable r1 = () -> ds.complete(1);
61-
62-
Runnable r2 = ds::cancel;
63-
64-
TestHelper.race(r1, r2);
65-
}
66-
}
67-
68-
@Test
69-
public void requestClearRace() {
70-
for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) {
71-
TestSubscriber<Integer> ts = new TestSubscriber<>(0L);
72-
73-
final DeferredScalarSubscription<Integer> ds = new DeferredScalarSubscription<>(ts);
74-
ts.onSubscribe(ds);
75-
ds.complete(1);
76-
77-
Runnable r1 = () -> ds.request(1);
78-
79-
Runnable r2 = () -> ds.value = null;
80-
81-
TestHelper.race(r1, r2);
82-
83-
if (!ts.values().isEmpty()) {
84-
ts.assertValue(1);
85-
}
86-
}
87-
}
88-
89-
@Test
90-
public void requestCancelRace() {
91-
for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) {
92-
TestSubscriber<Integer> ts = new TestSubscriber<>(0L);
93-
94-
final DeferredScalarSubscription<Integer> ds = new DeferredScalarSubscription<>(ts);
95-
ts.onSubscribe(ds);
96-
ds.complete(1);
97-
98-
Runnable r1 = () -> ds.request(1);
99-
100-
Runnable r2 = ds::cancel;
101-
102-
TestHelper.race(r1, r2);
103-
104-
if (!ts.values().isEmpty()) {
105-
ts.assertValue(1);
106-
}
107-
}
108-
}
10955
}

0 commit comments

Comments
 (0)