OSDN Git Service

Add Delay to ThreadTest#test_getState
authorBrian Muramatsu <btmura@android.com>
Tue, 28 Dec 2010 20:05:23 +0000 (12:05 -0800)
committerBrian Muramatsu <btmura@android.com>
Tue, 28 Dec 2010 20:41:08 +0000 (12:41 -0800)
Wait a bit before checking that the thread state is WAITING. A context
switch between updating the semaphore's internal state and invoking wait
can cause the test to see that the thread is still RUNNABLE.

Change-Id: Ie0ea934b83e6efe76b721289665bb20a13cd6eea

libcore/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadTest.java

index a24f457..7183bad 100644 (file)
@@ -1999,10 +1999,13 @@ public class ThreadTest extends junit.framework.TestCase {
 
         while (!sem.hasQueuedThreads()){}
         
+        long start = System.currentTimeMillis();
+        while(start + 1000 > System.currentTimeMillis()) {}
         assertEquals(Thread.State.WAITING, th.getState());
+
         synchronized (lock) {
             sem.release();
-            long start = System.currentTimeMillis();
+            start = System.currentTimeMillis();
             while(start + 1000 > System.currentTimeMillis()) {}
             assertEquals(Thread.State.BLOCKED, th.getState());
         }