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
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());
}