@Test
public void testConcatUnsubscribeConcurrent() {

    final CountDownLatch callOnce = new CountDownLatch(1);
    final CountDownLatch okToContinue = new CountDownLatch(1);
    final TestObservable<String> w1 = new TestObservable<String>("one", "two", "three");
    final TestObservable<String> w2 = new TestObservable<String>(callOnce, okToContinue, "four", "five", "six");
    @SuppressWarnings("unchecked")
    Observer<String> observer = mock(Observer.class);
    @SuppressWarnings("unchecked")
    TestObservable<Observable<String>> observableOfObservables = new TestObservable<Observable<String>>(Observable.create(w1), Observable.create(w2));
    Observable.OnSubscribeFunc<String> concatF = concat(Observable.create(observableOfObservables));
    Observable<String> concat = Observable.create(concatF);
    Subscription s1 = concat.subscribe(observer);
    try {
        //Block main thread to allow observable "w1" to complete and observable "w2" to call onNext exactly once.
        callOnce.await();
        //"four" from w2 has been processed by onNext()
        s1.unsubscribe();
        //"five" and "six" will NOT be processed by onNext()
        //Unblock the observable to continue.
        okToContinue.countDown();
        w1.t.join();
        w2.t.join();
    } catch (Throwable e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    InOrder inOrder = inOrder(observer);
    inOrder.verify(observer, times(1)).onNext("one");
    inOrder.verify(observer, times(1)).onNext("two");
    inOrder.verify(observer, times(1)).onNext("three");
    inOrder.verify(observer, times(1)).onNext("four");
    inOrder.verify(observer, never()).onNext("five");
    inOrder.verify(observer, never()).onNext("six");
    verify(observer, never()).onCompleted();
    verify(observer, never()).onError(any(Throwable.class));
}