--- jsr166/src/test/tck/ExecutorCompletionServiceTest.java 2011/03/15 19:47:06 1.13 +++ jsr166/src/test/tck/ExecutorCompletionServiceTest.java 2011/05/29 06:50:55 1.16 @@ -6,7 +6,6 @@ * Pat Fisher, Mike Judd. */ - import junit.framework.*; import java.util.*; import java.util.concurrent.*; @@ -23,7 +22,6 @@ public class ExecutorCompletionServiceTe return new TestSuite(ExecutorCompletionServiceTest.class); } - /** * Creating a new ECS with null Executor throw NPE */ @@ -112,21 +110,23 @@ public class ExecutorCompletionServiceTe /** * If poll returns non-null, the returned task is completed */ - public void testPoll1() throws InterruptedException { + public void testPoll1() throws Exception { ExecutorService e = Executors.newCachedThreadPool(); ExecutorCompletionService ecs = new ExecutorCompletionService(e); try { assertNull(ecs.poll()); Callable c = new StringTask(); ecs.submit(c); - Thread.sleep(SHORT_DELAY_MS); - for (;;) { - Future f = ecs.poll(); - if (f != null) { - assertTrue(f.isDone()); - break; - } + + long startTime = System.nanoTime(); + Future f; + while ((f = ecs.poll()) == null) { + if (millisElapsedSince(startTime) > LONG_DELAY_MS) + fail("timed out"); + Thread.yield(); } + assertTrue(f.isDone()); + assertSame(TEST_STRING, f.get()); } finally { joinPool(e); }