diff --git a/test/unit/voldemort/store/memory/SlowStorageEngineTest.java b/test/unit/voldemort/store/memory/SlowStorageEngineTest.java index dc5f4b6d41..8a9f523ffd 100644 --- a/test/unit/voldemort/store/memory/SlowStorageEngineTest.java +++ b/test/unit/voldemort/store/memory/SlowStorageEngineTest.java @@ -190,10 +190,10 @@ public void testEachOpTypeIndividually() { // Magic constant 60 ms is based on operation times defined above. long expectedMs = 60; - // Magic constants 50 and 5 below allow us to make sure a tight timing - // test passes 90% of the time. + // Magic constants 50 and 10 below allow us to make sure a tight timing + // test passes 80% of the time. int numOps = 50; - int numOpsWithBadTimesOK = 5; + int numOpsWithBadTimesOK = 10; for(byte op: opList) { int badTimesCounter = 0; for(int i = 0; i < numOps; ++i) { @@ -226,9 +226,13 @@ public void testEachOpTypeIndividually() { * Test repeated operations. */ public void testEachOpTypeRepeated() { - // Magic number '2': Run once to warm up, run again and test asserts on - // second pass + // Magic number '2': Run once to warm up, then tests timing asserts. for(int j = 0; j < 2; j++) { + // Magic constant 1 means we can have one op report a bad (tight) + // timing result + int numOpsWithBadTimesAllowed = 1; + int numOpsWithBadTimes = 0; + for(byte op: opList) { ConcurrentLinkedQueue runTimes = new ConcurrentLinkedQueue(); CountDownLatch waitForOps = new CountDownLatch(5 + 1); @@ -270,12 +274,16 @@ public void testEachOpTypeRepeated() { expectedTimeMs = (5 * 30) + 30; break; } - String details = "(maxTimeMs: " + maxTimeMs + ", " + expectedTimeMs + ")"; - assertFalse("OpInvoker operation time is bad " + details, - isRunTimeBad(maxTimeMs, expectedTimeMs)); + if(isRunTimeBad(maxTimeMs, expectedTimeMs)) { + numOpsWithBadTimes++; + String details = getOpName(op) + ", maxTimeMs: " + maxTimeMs + ", " + + expectedTimeMs; + System.err.println("Bad run time (some are expected): " + details); + } } + assertFalse("Too many operations with bad run times: " + numOpsWithBadTimes, + numOpsWithBadTimes > numOpsWithBadTimesAllowed); } } } - } diff --git a/test/unit/voldemort/utils/pool/KeyedResourcePoolTest.java b/test/unit/voldemort/utils/pool/KeyedResourcePoolTest.java index 3118ddd408..cc6625d857 100644 --- a/test/unit/voldemort/utils/pool/KeyedResourcePoolTest.java +++ b/test/unit/voldemort/utils/pool/KeyedResourcePoolTest.java @@ -37,7 +37,7 @@ public class KeyedResourcePoolTest { protected static int POOL_SIZE = 5; - protected static long TIMEOUT_MS = 200; + protected static long TIMEOUT_MS = 500; protected TestResourceFactory factory; protected KeyedResourcePool pool; diff --git a/test/unit/voldemort/utils/pool/QueuedKeyedResourcePoolTest.java b/test/unit/voldemort/utils/pool/QueuedKeyedResourcePoolTest.java index 489433a7a9..ebc9d55706 100644 --- a/test/unit/voldemort/utils/pool/QueuedKeyedResourcePoolTest.java +++ b/test/unit/voldemort/utils/pool/QueuedKeyedResourcePoolTest.java @@ -159,8 +159,13 @@ public void testQueuingStats() throws Exception { long startNs = System.nanoTime(); assertEquals(POOL_SIZE * 10000, this.queuedPool.getRegisteredResourceRequestCount()); - assertTrue("O(n) count of queue is too slow", - System.nanoTime() - startNs < TimeUnit.MILLISECONDS.toNanos(10)); + long durationNs = System.nanoTime() - startNs; + // 20 ms is an arbitrary time limit: + // POOL_SIZE * 10000 resource requests / 20 ms + // = 50000 resource requests/20ms + // = 2500 resource requests/ms + assertTrue("O(n) count of queue is too slow: " + durationNs + " ns.", + durationNs < TimeUnit.MILLISECONDS.toNanos(20)); // Confirm additional requests are queued assertEquals(POOL_SIZE, this.factory.getCreated());