question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

2.x: parallel blocks forever with TestScheduler

See original GitHub issue

io.reactivex.rxjava2:rxjava:2.2.3

public class DemoApplication {
   public static void main(String[] args) {
       List<Map.Entry<Integer, String>> entries = Arrays.asList(
               new AbstractMap.SimpleImmutableEntry<>(3, "hello"),
               new AbstractMap.SimpleImmutableEntry<>(3, "world")
       );

       Flowable.fromIterable(entries)
               .flatMap(entry -> Flowable.range(1, entry.getKey())
                       .parallel()
                       .runOn(Schedulers.io())
                       .flatMap(i -> logIt(entry.getValue()).toFlowable())
                       .sequential()
               )
               .all(success -> success)
               .doOnSuccess(success -> System.out.println("good"))
               .doOnError(Throwable::printStackTrace)
               .blockingGet();
   }

   private static Single<Boolean> logIt(String s) {
       System.out.println(s);

       return Single.just(true);
   }
}

This code works as expected. However, replacing Schedulers.io() with TestScheduler blocks forever. Gradle project attached.

demo.zip

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
akarnokdcommented, Jan 3, 2019

even if there’s no delay or interval in the code […] That wouldn’t be my first thought

TestScheduler captures tasks scheduled by operators so that side-effects can be performed before the task then gets executed on demand via advanceTimeBy, even if they are logically not delayed. In reality, there is always some non-zero time elapsing between the scheduling and execution of such task. TestScheduler just makes it deterministic.

if you do that here, I’ll be happy to send a PR for the docs.

If you wish to contribute, you could extend its JavaDocs with the explicit mention of advanceTimeBy or even a short example.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing RxJS Code with Marble Diagrams
We can test our asynchronous RxJS code synchronously and deterministically by virtualizing time using the TestScheduler. Marble diagrams provide a visual ...
Read more >
4. Applying Reactive Programming to Existing Applications
Operators on BlockingObservable typically block (wait) until the underlying Observable is completed. This strongly contradicts the main concept of Observable s ...
Read more >
Observable - Monix
The Observable is a data type for modeling and processing asynchronous and reactive streaming of events with non-blocking back-pressure.
Read more >
System.Reactive.Testing.TestScheduler for System.Threading ...
I have used System.Reactive.Testing.TestScheduler to test asynchronous code implemented using Observables before. I have now written code that ...
Read more >
PHP Reactive Programming
RxPHP 1.x and RxPHP 2. Summary. 2. Reactive Programming with RxPHP ... This will let us run our code in parallel in multiple...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found