@Test
  public void testInterruptTerminalEventAwaitAndUnsubscribe() {
    TestSubscriber<Integer> ts = TestSubscriber.create();

    final Thread t0 = Thread.currentThread();
    Worker w = Schedulers.computation().createWorker();
    try {
      w.schedule(
          new Action0() {
            @Override
            public void call() {
              t0.interrupt();
            }
          },
          200,
          TimeUnit.MILLISECONDS);

      ts.awaitTerminalEventAndUnsubscribeOnTimeout(5, TimeUnit.SECONDS);
      if (!ts.isUnsubscribed()) {
        fail("Did not unsubscribe!");
      }
    } finally {
      w.unsubscribe();
    }
  }
 @Test
 public void testAwaitTerminalEventWithDurationAndUnsubscribeOnTimeout() {
   TestSubscriber<Object> ts = new TestSubscriber<Object>();
   final AtomicBoolean unsub = new AtomicBoolean(false);
   Observable.just(1)
       //
       .doOnUnsubscribe(
           new Action0() {
             @Override
             public void call() {
               unsub.set(true);
             }
           })
       //
       .delay(1000, TimeUnit.MILLISECONDS)
       .subscribe(ts);
   ts.awaitTerminalEventAndUnsubscribeOnTimeout(100, TimeUnit.MILLISECONDS);
   assertTrue(unsub.get());
 }