From 37f3351b58110367c060a23ef4d5f5355fb2e8af Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Tue, 7 Apr 2015 13:34:08 +0200 Subject: [PATCH] Tests: Speed up CopyOnWriteHash(Map|Set)Tests These tests create artificial hash collisions in order to make sure that they can be resolved correctly. But this also makes the tests very slow if there are too many collisions because insertions/deletions become linear in such cases. The tests have been modified to not do too many iterations when collisions are likely. Close #10442 --- .../elasticsearch/common/collect/CopyOnWriteHashMapTests.java | 4 +++- .../elasticsearch/common/collect/CopyOnWriteHashSetTests.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/elasticsearch/common/collect/CopyOnWriteHashMapTests.java b/src/test/java/org/elasticsearch/common/collect/CopyOnWriteHashMapTests.java index c0e900b69d4..077970941f3 100644 --- a/src/test/java/org/elasticsearch/common/collect/CopyOnWriteHashMapTests.java +++ b/src/test/java/org/elasticsearch/common/collect/CopyOnWriteHashMapTests.java @@ -55,9 +55,11 @@ public class CopyOnWriteHashMapTests extends ElasticsearchTestCase { public void testDuel() { final int iters = scaledRandomIntBetween(2, 5); for (int iter = 0; iter < iters; ++iter) { - final int numOps = randomInt(5000); final int valueBits = randomIntBetween(1, 30); final int hashBits = randomInt(valueBits); + // we compute the total number of ops based on the bits of the hash + // since the test is much heavier when few bits are used for the hash + final int numOps = randomInt(10 + hashBits * 100); Map ref = new HashMap<>(); CopyOnWriteHashMap map = new CopyOnWriteHashMap<>(); diff --git a/src/test/java/org/elasticsearch/common/collect/CopyOnWriteHashSetTests.java b/src/test/java/org/elasticsearch/common/collect/CopyOnWriteHashSetTests.java index 49bca02f628..86e4611c398 100644 --- a/src/test/java/org/elasticsearch/common/collect/CopyOnWriteHashSetTests.java +++ b/src/test/java/org/elasticsearch/common/collect/CopyOnWriteHashSetTests.java @@ -55,9 +55,11 @@ public class CopyOnWriteHashSetTests extends ElasticsearchTestCase { public void testDuel() { final int iters = scaledRandomIntBetween(2, 5); for (int iter = 0; iter < iters; ++iter) { - final int numOps = randomInt(5000); final int valueBits = randomIntBetween(1, 30); final int hashBits = randomInt(valueBits); + // we compute the total number of ops based on the bits of the hash + // since the test is much heavier when few bits are used for the hash + final int numOps = randomInt(10 + hashBits * 100); Set ref = new HashSet<>(); CopyOnWriteHashSet set = new CopyOnWriteHashSet<>();