public static void waitForJobs(IJobMatcher matcher, int maxWaitMillis) { final long limit = System.currentTimeMillis() + maxWaitMillis; while (true) { Job job = getJob(matcher); if (job == null) { return; } boolean timeout = System.currentTimeMillis() > limit; Assert.assertFalse("Timeout while waiting for completion of job: " + job, timeout); job.wakeUp(); try { Thread.sleep(POLLING_DELAY); } catch (InterruptedException e) { // ignore and keep waiting } } }