Skip to content

Commit 6163f98

Browse files
committed
Wait for watcher to be started prior to rolling upgrade tests. (elastic#52139)
In the rolling upgrade tests, watcher is manually executed, in rare scenarios this happens before watcher is started, resulting in the manual execution to fail. Relates to elastic#33185
1 parent 2f1631d commit 6163f98

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/UpgradeClusterClientYamlTestSuiteIT.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
99
import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;
1010
import org.apache.lucene.util.TimeUnits;
11+
import org.elasticsearch.client.Request;
12+
import org.elasticsearch.client.Response;
1113
import org.elasticsearch.common.settings.Settings;
1214
import org.elasticsearch.common.util.concurrent.ThreadContext;
1315
import org.elasticsearch.test.rest.ESRestTestCase;
@@ -19,6 +21,10 @@
1921

2022
import java.nio.charset.StandardCharsets;
2123
import java.util.Base64;
24+
import java.util.List;
25+
import java.util.Map;
26+
27+
import static org.hamcrest.Matchers.equalTo;
2228

2329

2430
@TimeoutSuite(millis = 5 * TimeUnits.MINUTE) // to account for slow as hell VMs
@@ -32,6 +38,21 @@ public void waitForTemplates() throws Exception {
3238
XPackRestTestHelper.waitForTemplates(client(), XPackRestTestConstants.ML_POST_V660_TEMPLATES);
3339
}
3440

41+
@Before
42+
public void waitForWatcher() throws Exception {
43+
// Wait for watcher to be in started state in order to avoid errors due
44+
// to manually executing watches prior for watcher to be ready:
45+
assertBusy(() -> {
46+
Response response = client().performRequest(new Request("GET", "_watcher/stats"));
47+
Map<String, Object> responseBody = entityAsMap(response);
48+
List<?> stats = (List<?>) responseBody.get("stats");
49+
for (Object stat : stats) {
50+
Map<?, ?> statAsMap = (Map<?, ?>) stat;
51+
assertThat(statAsMap.get("watcher_state"), equalTo("started"));
52+
}
53+
});
54+
}
55+
3556
@Override
3657
protected boolean preserveIndicesUponCompletion() {
3758
return true;

0 commit comments

Comments
 (0)