2.x: parallel blocks forever with TestScheduler
See original GitHub issueio.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.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
TestScheduler
captures tasks scheduled by operators so that side-effects can be performed before the task then gets executed on demand viaadvanceTimeBy
, 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 wish to contribute, you could extend its JavaDocs with the explicit mention of
advanceTimeBy
or even a short example.@akarnokd https://github.com/ReactiveX/RxJava/pull/6356