@Test
public void testTrampolineWorkerHandlesConcurrentScheduling() {

    final Worker trampolineWorker = Schedulers.trampoline().createWorker();
    final Observer<Subscription> observer = Observers.empty();
    final TestSubscriber<Subscription> ts = new TestSubscriber<Subscription>(observer);
    // Spam the trampoline with actions.
    Observable.range(0, 50)
            .flatMap(new Func1<Integer, Observable<Subscription>>() {
                @Override
                public Observable<Subscription> call(Integer count) {
                    return Observable.interval(1, TimeUnit.MICROSECONDS).map(
                            new Func1<Long, Subscription>() {
                                 @Override
                                 public Subscription call(Long count) {
                                     return trampolineWorker.schedule(new Action0() {
                                         @Override
                                         public void call() {}
                                     });
                                 }
                            }).limit(100);
                }
            })
            .subscribeOn(Schedulers.computation())
            .subscribe(ts);
    ts.awaitTerminalEvent();
    ts.assertNoErrors();
}