/**
  * Waits for the specified time (in milliseconds) for the thread to terminate (using {@link
  * Thread#join(long)}), else interrupts the thread (in the hope that it may terminate later) and
  * fails.
  */
 void awaitTermination(Thread t, long timeoutMillis) {
   try {
     t.join(timeoutMillis);
   } catch (InterruptedException ie) {
     threadUnexpectedException(ie);
   } finally {
     if (t.getState() != Thread.State.TERMINATED) {
       t.interrupt();
       fail("Test timed out");
     }
   }
 }