Browse Source

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

Simon Willnauer 9 years ago
parent
commit
62b821ccf4

+ 3 - 2
core/src/test/java/org/elasticsearch/common/util/concurrent/AsyncIOProcessorTests.java

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

+ 1 - 1
core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java

@@ -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) {