Skip to content

Commit 974b4ad

Browse files
Changed to use SubscribeOn instead of ObserveOn for Async Behavior
The ObserveOn operator is for moving where it executes, not making it async. SubscribeOn makes it async.
1 parent c758d13 commit 974b4ad

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ public void onNext(String v) {
311311
subject.onNext("two");
312312
assertEquals("two", lastValueForObserver1.get());
313313

314-
Subscription s2 = subject.observeOn(Schedulers.newThread()).subscribe(observer2);
314+
// use subscribeOn to make this async otherwise we deadlock as we are using CountDownLatches
315+
Subscription s2 = subject.subscribeOn(Schedulers.newThread()).subscribe(observer2);
315316

316317
System.out.println("before waiting for one");
317318

@@ -321,12 +322,23 @@ public void onNext(String v) {
321322
System.out.println("after waiting for one");
322323

323324
subject.onNext("three");
325+
326+
System.out.println("sent three");
327+
324328
// if subscription blocked existing subscribers then 'makeSlow' would cause this to not be there yet
325329
assertEquals("three", lastValueForObserver1.get());
330+
331+
System.out.println("about to send onCompleted");
332+
326333
subject.onCompleted();
327334

335+
System.out.println("completed subject");
336+
328337
// release
329338
makeSlow.countDown();
339+
340+
System.out.println("makeSlow released");
341+
330342
completed.await();
331343
// all of them should be emitted with the last being "three"
332344
assertEquals("three", lastValueForObserver2.get());

0 commit comments

Comments
 (0)