Skip to content

Commit 08ff448

Browse files
authored
[Test] More robust assertions for watcher execution (#76977) (#77000)
Since the test is really for making sure the serialised authentication header can work after cluster upgrade, it is sufficient to just assert that the watcher execute successfully once regardless of the total number of execution.
1 parent a4d9c1b commit 08ff448

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import java.util.Locale;
5050
import java.util.Map;
5151
import java.util.concurrent.TimeUnit;
52+
import java.util.concurrent.atomic.AtomicBoolean;
5253
import java.util.stream.Collectors;
5354

5455
import static org.elasticsearch.core.TimeValue.timeValueSeconds;
@@ -59,7 +60,6 @@
5960
import static org.hamcrest.Matchers.containsString;
6061
import static org.hamcrest.Matchers.equalTo;
6162
import static org.hamcrest.Matchers.everyItem;
62-
import static org.hamcrest.Matchers.greaterThan;
6363
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
6464
import static org.hamcrest.Matchers.hasEntry;
6565
import static org.hamcrest.Matchers.hasItems;
@@ -231,7 +231,6 @@ public void testWatcher() throws Exception {
231231
}
232232
}
233233

234-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/63088")
235234
@SuppressWarnings("unchecked")
236235
public void testWatcherWithApiKey() throws Exception {
237236
assumeTrue("API key is available since 6.7.0", getOldClusterVersion().onOrAfter(Version.V_6_7_0));
@@ -252,7 +251,6 @@ public void testWatcherWithApiKey() throws Exception {
252251

253252
assertBusy(() -> {
254253
final Request getRequest = new Request("GET", getWatcherEndpoint() + "/watch/watch_with_api_key");
255-
getRequest.addParameter("filter_path", "status");
256254
final Map<String, Object> getWatchStatusResponse = entityAsMap(client().performRequest(getRequest));
257255
final Map<String, Object> status = (Map<String, Object>) getWatchStatusResponse.get("status");
258256
assertEquals("executed", status.get("execution_state"));
@@ -273,7 +271,6 @@ public void testWatcherWithApiKey() throws Exception {
273271

274272
try {
275273
final Request getWatchStatusRequest = new Request("GET", "_watcher/watch/watch_with_api_key");
276-
getWatchStatusRequest.addParameter("filter_path", "status");
277274
if (getOldClusterVersion().before(Version.V_7_0_0)) {
278275
getWatchStatusRequest.setOptions(
279276
expectWarnings(
@@ -285,11 +282,19 @@ public void testWatcherWithApiKey() throws Exception {
285282
final Map<String, Object> status = (Map<String, Object>) getWatchStatusResponse.get("status");
286283
final int version = (int) status.get("version");
287284

285+
final AtomicBoolean versionIncreased = new AtomicBoolean();
286+
final AtomicBoolean executed = new AtomicBoolean();
288287
assertBusy(() -> {
289288
final Map<String, Object> newGetWatchStatusResponse = entityAsMap(client().performRequest(getWatchStatusRequest));
290289
final Map<String, Object> newStatus = (Map<String, Object>) newGetWatchStatusResponse.get("status");
291-
assertThat((int) newStatus.get("version"), greaterThan(version + 2));
292-
assertEquals("executed", newStatus.get("execution_state"));
290+
if (false == versionIncreased.get() && version < (int) newStatus.get("version")) {
291+
versionIncreased.set(true);
292+
}
293+
if (false == executed.get() && "executed".equals(newStatus.get("execution_state"))) {
294+
executed.set(true);
295+
}
296+
assertThat("version increased: [" + versionIncreased.get() + "], executed: [" + executed.get() + "]",
297+
versionIncreased.get() && executed.get(), is(true));
293298
});
294299
} finally {
295300
stopWatcher();

0 commit comments

Comments
 (0)