[TEST] Ensure test never hangs but fails if it doesn't finish after 10 seconds waiting for threads

This commit is contained in:
Simon Willnauer 2016-08-27 23:20:55 +02:00
parent 162ad1251c
commit 62b821ccf4
2 changed files with 4 additions and 3 deletions

View File

@ -25,6 +25,7 @@ import java.io.IOException;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
@ -73,7 +74,7 @@ public class AsyncIOProcessorTests extends ESTestCase {
for (int i = 0; i < thread.length; i++) {
thread[i].join();
}
semaphore.acquire(Integer.MAX_VALUE);
assertTrue(semaphore.tryAcquire(Integer.MAX_VALUE, 10, TimeUnit.SECONDS));
assertEquals(count * thread.length, received.get());
}
@ -126,7 +127,7 @@ public class AsyncIOProcessorTests extends ESTestCase {
for (int i = 0; i < thread.length; i++) {
thread[i].join();
}
semaphore.acquire(Integer.MAX_VALUE);
assertTrue(semaphore.tryAcquire(Integer.MAX_VALUE, 10, TimeUnit.SECONDS));
assertEquals(count * thread.length, received.get());
assertEquals(actualFailed.get(), failed.get());
}

View File

@ -615,7 +615,7 @@ public class IndexShardTests extends ESSingleNodeTestCase {
for (int i = 0; i < thread.length; i++) {
thread[i].join();
}
semaphore.acquire(Integer.MAX_VALUE);
assertTrue(semaphore.tryAcquire(Integer.MAX_VALUE, 10, TimeUnit.SECONDS));
}
private void setDurability(IndexShard shard, Translog.Durability durability) {