From 3f541fa5566e623f3fc7263b47e1efc7bdbf4727 Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Tue, 22 Aug 2017 00:39:11 +0200 Subject: [PATCH] Tests: Ensure watcher is started via awaitBusy in bwc test Original commit: elastic/x-pack-elasticsearch@a8c0cf04c9d2312090cf373cf5f327c75a5bf4a1 --- .../WatchBackwardsCompatibilityIT.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/WatchBackwardsCompatibilityIT.java b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/WatchBackwardsCompatibilityIT.java index 564242f1b5b..521f107f45c 100644 --- a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/WatchBackwardsCompatibilityIT.java +++ b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/WatchBackwardsCompatibilityIT.java @@ -187,15 +187,7 @@ public class WatchBackwardsCompatibilityIT extends ESRestTestCase { ensureWatcherStopped(); executeAgainstRandomNode(client -> assertOK(client.performRequest("POST", "/_xpack/watcher/_start"))); - executeAgainstMasterNode(client -> assertBusy(() -> { - Response response = client.performRequest("GET", "_xpack/watcher/stats"); - String responseBody = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); - // TODO once the serialization fix is in here, we can check for concrete fields if the run against a 5.x or a 6.x node - // using a checkedbiconsumer, that provides info against which node the request runs - assertThat(responseBody, not(containsString("\"watcher_state\":\"starting\""))); - assertThat(responseBody, not(containsString("\"watcher_state\":\"stopping\""))); - assertThat(responseBody, not(containsString("\"watcher_state\":\"stopped\""))); - })); + ensureWatcherStarted(); } public void testWatchCrudApis() throws Exception { @@ -260,6 +252,7 @@ public class WatchBackwardsCompatibilityIT extends ESRestTestCase { ensureWatcherStopped(); assertOK(client.performRequest("POST", "/_xpack/watcher/_start")); logger.info("started watcher manually after running upgrade"); + ensureWatcherStarted(); } } } @@ -311,6 +304,16 @@ public class WatchBackwardsCompatibilityIT extends ESRestTestCase { })); } + private void ensureWatcherStarted() throws Exception { + executeAgainstMasterNode(client -> assertBusy(() -> { + Response response = client.performRequest("GET", "_xpack/watcher/stats"); + String responseBody = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); + assertThat(responseBody, not(containsString("\"watcher_state\":\"starting\""))); + assertThat(responseBody, not(containsString("\"watcher_state\":\"stopping\""))); + assertThat(responseBody, not(containsString("\"watcher_state\":\"stopped\""))); + })); + } + private void assertOK(Response response) throws IOException { assertThat(response.getStatusLine().getStatusCode(), anyOf(equalTo(200), equalTo(201))); // consume that entity, otherwise the input stream will not be closed