--- jsr166/src/test/tck/ExecutorCompletionServiceTest.java 2011/03/15 19:47:06 1.13 +++ jsr166/src/test/tck/ExecutorCompletionServiceTest.java 2011/05/29 06:54:23 1.17 @@ -6,13 +6,11 @@ * Pat Fisher, Mike Judd. */ - import junit.framework.*; import java.util.*; import java.util.concurrent.*; import static java.util.concurrent.TimeUnit.MILLISECONDS; import java.util.concurrent.atomic.*; -import java.math.BigInteger; import java.security.*; public class ExecutorCompletionServiceTest extends JSR166TestCase { @@ -23,7 +21,6 @@ public class ExecutorCompletionServiceTe return new TestSuite(ExecutorCompletionServiceTest.class); } - /** * Creating a new ECS with null Executor throw NPE */ @@ -112,21 +109,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); }