@Test
public void disposeRace() {

    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        final AtomicReference<Disposable> ref = new AtomicReference<Disposable>();
        final ConnectableFlowable<Integer> cf = new Flowable<Integer>() {
            @Override
            protected void subscribeActual(Subscriber<? super Integer> s) {
                s.onSubscribe(new BooleanSubscription());
                ref.set((Disposable)s);
            }
        }.publish();
        cf.connect();
        Runnable r1 = new Runnable() {
            @Override
            public void run() {
                ref.get().dispose();
            }
        };
        TestHelper.race(r1, r1);
    }
}