@Test
public void testConnectInterrupted() throws InterruptedException {

  long startTimeMs = SystemClock.elapsedRealtime();
  final ConditionVariable startCondition = buildUrlRequestStartedCondition();
  final CountDownLatch timedOutLatch = new CountDownLatch(1);
  Thread thread =
      new Thread() {
        @Override
        public void run() {
          try {
            dataSourceUnderTest.open(testDataSpec);
            fail();
          } catch (HttpDataSourceException e) {
            // Expected.
            assertThat(e instanceof CronetDataSource.OpenException).isTrue();
            assertThat(e.getCause() instanceof CronetDataSource.InterruptedIOException).isTrue();
            assertThat(((CronetDataSource.OpenException) e).cronetConnectionStatus)
                .isEqualTo(TEST_INVALID_CONNECTION_STATUS);
            timedOutLatch.countDown();
          }
        }
      };
  thread.start();
  startCondition.block();
  // We should still be trying to open.
  assertNotCountedDown(timedOutLatch);
  // We should still be trying to open as we approach the timeout.
  SystemClock.setCurrentTimeMillis(startTimeMs + TEST_CONNECT_TIMEOUT_MS - 1);
  assertNotCountedDown(timedOutLatch);
  // Now we interrupt.
  thread.interrupt();
  timedOutLatch.await();
  verify(mockTransferListener, never())
      .onTransferStart(dataSourceUnderTest, testDataSpec, /* isNetwork= */ true);
}