summaryrefslogtreecommitdiffstats
path: root/container-search
diff options
context:
space:
mode:
authorArne H Juul <arnej@yahoo-inc.com>2016-07-25 13:42:16 +0200
committerArne H Juul <arnej@yahoo-inc.com>2016-07-25 13:42:16 +0200
commitbf993166f43dde6f7f67c5d61612854250556f1d (patch)
tree1495a7386117ef63df936b673107ec00a3f22771 /container-search
parent45b5d7dfd10502fba4f4540037be7899266166c2 (diff)
add retries in timing-dependent test
* if too much time passes between putting thing into the cache and taking them out again, they might be removed as "too old". Measure the time around the critical region and retry if it was possibly too long.
Diffstat (limited to 'container-search')
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/cache/test/CacheTestCase.java20
1 files changed, 16 insertions, 4 deletions
diff --git a/container-search/src/test/java/com/yahoo/prelude/cache/test/CacheTestCase.java b/container-search/src/test/java/com/yahoo/prelude/cache/test/CacheTestCase.java
index 668603fce29..bd1777bd75e 100644
--- a/container-search/src/test/java/com/yahoo/prelude/cache/test/CacheTestCase.java
+++ b/container-search/src/test/java/com/yahoo/prelude/cache/test/CacheTestCase.java
@@ -130,10 +130,22 @@ public class CacheTestCase extends TestCase {
public void testExpire() throws InterruptedException {
Cache cache=new Cache(10*1024,50, 10000, Statistics.nullImplementation); // 10 KB, 50ms expire
- cache.put("foo", "bar");
- cache.put("hey", "ho");
- assertEquals(cache.get("foo"), "bar");
- assertEquals(cache.get("hey"), "ho");
+ boolean success = false;
+ for (int tries = 0; tries < 10; tries++) {
+ long before = System.currentTimeMillis();
+ cache.put("foo", "bar");
+ cache.put("hey", "ho");
+ Object got1 = cache.get("foo");
+ Object got2 = cache.get("hey");
+ long after = System.currentTimeMillis();
+ if (after - before < 50) {
+ assertEquals(got1, "bar");
+ assertEquals(got2, "ho");
+ success = true;
+ break;
+ }
+ }
+ assertTrue(success);
Thread.sleep(100);
assertNull(cache.get("foo"));
assertNull(cache.get("hey"));