NO-JIRA Fixing rare intermittent failure on CreditsSemaphoreTest
This commit is contained in:
parent
500066621e
commit
c1be566c20
|
@ -60,12 +60,7 @@ public class CreditsSemaphoreTest {
|
||||||
|
|
||||||
Assert.assertEquals(0, semaphore.getCredits());
|
Assert.assertEquals(0, semaphore.getCredits());
|
||||||
|
|
||||||
long timeout = System.currentTimeMillis() + 1000;
|
validateQueuedThreads();
|
||||||
while (!semaphore.hasQueuedThreads() && System.currentTimeMillis() < timeout) {
|
|
||||||
Thread.sleep(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
Assert.assertTrue(semaphore.hasQueuedThreads());
|
|
||||||
|
|
||||||
semaphore.setCredits(2);
|
semaphore.setCredits(2);
|
||||||
|
|
||||||
|
@ -76,6 +71,21 @@ public class CreditsSemaphoreTest {
|
||||||
Assert.assertFalse(semaphore.hasQueuedThreads());
|
Assert.assertFalse(semaphore.hasQueuedThreads());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void validateQueuedThreads() throws InterruptedException {
|
||||||
|
boolean hasQueueThreads = false;
|
||||||
|
long timeout = System.currentTimeMillis() + 5000;
|
||||||
|
while (System.currentTimeMillis() < timeout) {
|
||||||
|
|
||||||
|
if (semaphore.hasQueuedThreads()) {
|
||||||
|
hasQueueThreads = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Thread.sleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.assertTrue(hasQueueThreads);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDownAndUp() throws Exception {
|
public void testDownAndUp() throws Exception {
|
||||||
thread.start();
|
thread.start();
|
||||||
|
@ -114,12 +124,7 @@ public class CreditsSemaphoreTest {
|
||||||
|
|
||||||
Assert.assertEquals(0, semaphore.getCredits());
|
Assert.assertEquals(0, semaphore.getCredits());
|
||||||
|
|
||||||
long timeout = System.currentTimeMillis() + 1000;
|
validateQueuedThreads();
|
||||||
while (!semaphore.hasQueuedThreads() && System.currentTimeMillis() < timeout) {
|
|
||||||
Thread.sleep(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
Assert.assertTrue(semaphore.hasQueuedThreads());
|
|
||||||
|
|
||||||
Assert.assertEquals(0, acquired.get());
|
Assert.assertEquals(0, acquired.get());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue