Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Changes to make tight timing tests for QueuedKeyedResourcePool and Sl…
…owStorageEngine less sensitive on slower machines.
  • Loading branch information
jayjwylie committed Oct 9, 2012
1 parent e070703 commit 1890420
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
26 changes: 17 additions & 9 deletions test/unit/voldemort/store/memory/SlowStorageEngineTest.java
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<Long> runTimes = new ConcurrentLinkedQueue<Long>();
CountDownLatch waitForOps = new CountDownLatch(5 + 1);
Expand Down Expand Up @@ -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);
}
}
}

}
2 changes: 1 addition & 1 deletion test/unit/voldemort/utils/pool/KeyedResourcePoolTest.java
Expand Up @@ -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<String, TestResource> pool;
Expand Down
Expand Up @@ -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());
Expand Down

0 comments on commit 1890420

Please sign in to comment.