Skip to content

Commit 4f55f95

Browse files
ReplaySubject testRaceForTerminalState()
1 parent 42fa5aa commit 4f55f95

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

rxjava-core/src/test/java/rx/subjects/ReplaySubjectConcurrencyTest.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717

1818
import static org.junit.Assert.assertEquals;
1919

20-
import java.util.ArrayList;
21-
import java.util.Collections;
22-
import java.util.List;
20+
import java.util.*;
2321
import java.util.concurrent.CountDownLatch;
2422
import java.util.concurrent.TimeUnit;
2523
import java.util.concurrent.atomic.AtomicReference;
@@ -32,6 +30,8 @@
3230
import rx.Subscriber;
3331
import rx.Subscription;
3432
import rx.functions.Action1;
33+
import rx.observers.TestSubscriber;
34+
import rx.schedulers.Schedulers;
3535
import rx.subscriptions.Subscriptions;
3636

3737
public class ReplaySubjectConcurrencyTest {
@@ -303,6 +303,21 @@ public void run() {
303303
}
304304

305305
}
306+
307+
/**
308+
* https://github.com/Netflix/RxJava/issues/1147
309+
*/
310+
@Test
311+
public void testRaceForTerminalState() {
312+
final List<Integer> expected = Arrays.asList(1);
313+
for (int i = 0; i < 100000; i++) {
314+
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
315+
Observable.just(1).subscribeOn(Schedulers.computation()).cache().subscribe(ts);
316+
ts.awaitTerminalEvent();
317+
ts.assertReceivedOnNext(expected);
318+
ts.assertTerminalEvent();
319+
}
320+
}
306321

307322
private static class SubjectObserverThread extends Thread {
308323

0 commit comments

Comments
 (0)