[TEST] Make filestructurefinder.TimeoutCheckerTests more robust

This commit is contained in:
David Roberts 2018-12-14 22:28:12 +00:00
parent 3065300434
commit 2dd56cf945
1 changed files with 8 additions and 6 deletions

View File

@ -63,7 +63,7 @@ public class TimeoutCheckerTests extends FileStructureTestCase {
assertFalse(Thread.interrupted());
TimeValue timeout = TimeValue.timeValueMillis(1);
TimeValue timeout = TimeValue.timeValueMillis(100);
try (TimeoutChecker timeoutChecker = new TimeoutChecker("watchdog test", timeout, scheduler)) {
TimeoutChecker.watchdog.register();
@ -75,7 +75,7 @@ public class TimeoutCheckerTests extends FileStructureTestCase {
}
}
public void testGrokCaptures() {
public void testGrokCaptures() throws Exception {
assertFalse(Thread.interrupted());
Grok grok = new Grok(Grok.getBuiltinPatterns(), "{%DATA:data}{%GREEDYDATA:greedydata}", TimeoutChecker.watchdog);
@ -83,10 +83,12 @@ public class TimeoutCheckerTests extends FileStructureTestCase {
TimeValue timeout = TimeValue.timeValueMillis(1);
try (TimeoutChecker timeoutChecker = new TimeoutChecker("grok captures test", timeout, scheduler)) {
ElasticsearchTimeoutException e = expectThrows(ElasticsearchTimeoutException.class,
() -> timeoutChecker.grokCaptures(grok, randomAlphaOfLength(1000000), "should timeout"));
assertEquals("Aborting grok captures test during [should timeout] as it has taken longer than the timeout of [" +
timeout + "]", e.getMessage());
assertBusy(() -> {
ElasticsearchTimeoutException e = expectThrows(ElasticsearchTimeoutException.class,
() -> timeoutChecker.grokCaptures(grok, randomAlphaOfLength(1000000), "should timeout"));
assertEquals("Aborting grok captures test during [should timeout] as it has taken longer than the timeout of [" +
timeout + "]", e.getMessage());
});
}
}
}