@Test
public void testDeleteCgroup() throws Exception {

  final ControlledClock clock = new ControlledClock();
  CgroupsLCEResourcesHandler handler = new CgroupsLCEResourcesHandler();
  handler.setConf(new YarnConfiguration());
  handler.initConfig();
  handler.clock = clock;
  FileUtils.deleteQuietly(cgroupDir);
  // Create a non-empty tasks file
  File tfile = new File(cgroupDir.getAbsolutePath(), "tasks");
  FileOutputStream fos = FileUtils.openOutputStream(tfile);
  fos.write("1234".getBytes());
  fos.close();
  final CountDownLatch latch = new CountDownLatch(1);
  new Thread() {
    @Override
    public void run() {
      latch.countDown();
      try {
        Thread.sleep(200);
      } catch (InterruptedException ex) {
        //NOP
      }
      clock.tickMsec(YarnConfiguration.
          DEFAULT_NM_LINUX_CONTAINER_CGROUPS_DELETE_TIMEOUT);
    }
  }.start();
  latch.await();
  Assert.assertFalse(handler.deleteCgroup(cgroupDir.getAbsolutePath()));
  FileUtils.deleteQuietly(cgroupDir);
}