Merge pull request #1611 from metamx/betterTimingTests2789

Better handling of slow stuff in NamespaceExtractionCacheManagerExecutorsTest
This commit is contained in:
Fangjin Yang 2015-08-07 15:39:04 -07:00
commit 2d22bcc11b
1 changed files with 15 additions and 2 deletions

View File

@ -280,6 +280,7 @@ public class NamespaceExtractionCacheManagerExecutorsTest
null null
); );
final String cacheId = UUID.randomUUID().toString(); final String cacheId = UUID.randomUUID().toString();
final CountDownLatch latchBeforeMore = new CountDownLatch(1);
ListenableFuture<?> future = ListenableFuture<?> future =
manager.schedule( manager.schedule(
namespace, factory, new Runnable() namespace, factory, new Runnable()
@ -301,17 +302,29 @@ public class NamespaceExtractionCacheManagerExecutorsTest
} }
finally { finally {
latch.countDown(); latch.countDown();
latchMore.countDown(); try {
if (latch.getCount() == 0) {
latchBeforeMore.await();
}
}
catch (InterruptedException e) {
log.debug("Interrupted");
Thread.currentThread().interrupt();
}
finally {
latchMore.countDown();
}
} }
} }
}, },
cacheId cacheId
); );
latch.await(); latch.await();
prior = runs.get();
latchBeforeMore.countDown();
Assert.assertFalse(future.isCancelled()); Assert.assertFalse(future.isCancelled());
Assert.assertFalse(future.isDone()); Assert.assertFalse(future.isDone());
Assert.assertTrue(fnCache.containsKey(ns)); Assert.assertTrue(fnCache.containsKey(ns));
prior = runs.get();
latchMore.await(); latchMore.await();
Assert.assertTrue(runs.get() > prior); Assert.assertTrue(runs.get() > prior);