title: Unit test succeeds in debug mode but fails when running it normally
body: <p>Why does my unit test succeed in debug mode but fail when running it normally?</p>
  
  <pre><code>public class ExecutorServiceTest extends MockitoTestCase{   
    private int numThreads;
    private ExecutorService pool;
    private volatile boolean interruptedBitSet;
  
    @Override
    public void setUp() {
      numThreads = 5;
      pool = Executors.newFixedThreadPool(numThreads);
    }
  
  class TaskChecksForInterruptedBit implements Callable&lt;String&gt; {
      @Override
      public String call() throws Exception {
        interruptedBitSet = false;
        while (!Thread.currentThread().isInterrupted()) {
        }
        interruptedBitSet = Thread.currentThread().isInterrupted();
        return "blah";
      }
    }
  
  public void testCancelSetsInterruptedBitInCallable() throws Exception {
      interruptedBitSet = false;
      final Future&lt;String&gt; future = 
          pool.submit(new TaskChecksForInterruptedBit());
      final boolean wasJustCancelled = future.cancel(true);
      assertTrue(wasJustCancelled);
  
      // Give time for the thread to notice the interrupted bit and set the flag
      Thread.sleep(5000);
  
      // This succeeds when stepping through w/ a debugger, but fails when running
      // the test straight. WHY?
      assertTrue(interruptedBitSet);
  
      assertTrue(future.isDone());
      assertTrue(future.isCancelled());
    }
  }
  </code></pre>