NO-JIRA Fixing rare intermittent failure on CreditsSemaphoreTest

This commit is contained in:
Clebert Suconic 2020-07-08 12:36:26 -04:00
parent 500066621e
commit c1be566c20
1 changed files with 17 additions and 12 deletions

View File

@ -60,12 +60,7 @@ public class CreditsSemaphoreTest {
Assert.assertEquals(0, semaphore.getCredits());
long timeout = System.currentTimeMillis() + 1000;
while (!semaphore.hasQueuedThreads() && System.currentTimeMillis() < timeout) {
Thread.sleep(10);
}
Assert.assertTrue(semaphore.hasQueuedThreads());
validateQueuedThreads();
semaphore.setCredits(2);
@ -76,6 +71,21 @@ public class CreditsSemaphoreTest {
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
public void testDownAndUp() throws Exception {
thread.start();
@ -114,12 +124,7 @@ public class CreditsSemaphoreTest {
Assert.assertEquals(0, semaphore.getCredits());
long timeout = System.currentTimeMillis() + 1000;
while (!semaphore.hasQueuedThreads() && System.currentTimeMillis() < timeout) {
Thread.sleep(10);
}
Assert.assertTrue(semaphore.hasQueuedThreads());
validateQueuedThreads();
Assert.assertEquals(0, acquired.get());