Skip to content

Commit aa451ef

Browse files
akarnokdakarnokd
akarnokd
authored and
akarnokd
committed
Fixed race in testConnectUnsubscribeRaceCondition()
1 parent 0244223 commit aa451ef

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/test/java/rx/internal/operators/OnSubscribeRefCountTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ public void call() {
270270
s.assertNoErrors();
271271
}
272272

273+
@Test
274+
public void testConnectUnsubscribeRaceConditionLoop() throws InterruptedException {
275+
for (int i = 0; i < 1000; i++) {
276+
testConnectUnsubscribeRaceCondition();
277+
}
278+
}
279+
273280
@Test
274281
public void testConnectUnsubscribeRaceCondition() throws InterruptedException {
275282
final AtomicInteger subUnsubCount = new AtomicInteger();
@@ -295,12 +302,14 @@ public void call() {
295302
});
296303

297304
TestSubscriber<Long> s = new TestSubscriber<Long>();
298-
o.publish().refCount().subscribeOn(Schedulers.newThread()).subscribe(s);
305+
306+
o.publish().refCount().subscribeOn(Schedulers.computation()).subscribe(s);
299307
System.out.println("send unsubscribe");
300308
// now immediately unsubscribe while subscribeOn is racing to subscribe
301309
s.unsubscribe();
302310
// this generally will mean it won't even subscribe as it is already unsubscribed by the time connect() gets scheduled
303-
311+
// give time to the counter to update
312+
Thread.sleep(1);
304313
// either we subscribed and then unsubscribed, or we didn't ever even subscribe
305314
assertEquals(0, subUnsubCount.get());
306315

0 commit comments

Comments
 (0)