Tests: Ensure watcher is started in REST tests (elastic/x-pack-elasticsearch#1702)

This adds a check in the REST tests to ensure that
watcher is started, and if not, tries to start watcher.

This eliminates test failures where watcher was not in
the correct state due to other tests stopping watcher.

Original commit: elastic/x-pack-elasticsearch@fc547d49b4
This commit is contained in:
Alexander Reelsen 2017-06-14 08:34:09 +02:00 committed by GitHub
parent abe217ebc3
commit 4346431156
1 changed files with 32 additions and 1 deletions

View File

@ -33,6 +33,7 @@ import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static org.hamcrest.Matchers.is;
/** Runs rest tests against external cluster */
public class XPackRestIT extends XPackRestTestCase {
@ -56,6 +57,24 @@ public class XPackRestIT extends XPackRestTestCase {
response -> true,
() -> "Exception when waiting for [" + template + "] template to be created");
}
// ensure watcher is started, so that a test can stop watcher and everything still works fine
if (isWatcherTest()) {
assertBusy(() -> {
try {
ClientYamlTestResponse response =
getAdminExecutionContext().callApi("xpack.watcher.stats", emptyMap(), emptyList(), emptyMap());
String state = (String) response.evaluate("stats.0.watcher_state");
if ("started".equals(state) == false) {
getAdminExecutionContext().callApi("xpack.watcher.start", emptyMap(), emptyList(), emptyMap());
}
// assertion required to exit the assertBusy lambda
assertThat(state, is("started"));
} catch (IOException e) {
throw new AssertionError(e);
}
});
}
}
/**
@ -158,7 +177,9 @@ public class XPackRestIT extends XPackRestTestCase {
* thing and could be moved into a general X-Pack method at some point).
*/
private void clearMlState() throws Exception {
new MlRestTestStateCleaner(logger, adminClient(), this).clearMlMetadata();
if (isMachineLearningTest()) {
new MlRestTestStateCleaner(logger, adminClient(), this).clearMlMetadata();
}
}
/**
@ -201,4 +222,14 @@ public class XPackRestIT extends XPackRestTestCase {
String testName = getTestName();
return testName != null && (testName.contains("=monitoring/") || testName.contains("=monitoring\\"));
}
private boolean isWatcherTest() {
String testName = getTestName();
return testName != null && (testName.contains("=watcher/") || testName.contains("=watcher\\"));
}
private boolean isMachineLearningTest() {
String testName = getTestName();
return testName != null && (testName.contains("=ml/") || testName.contains("=ml\\"));
}
}