Skip to content

Commit c605cdf

Browse files
authored
[Test] More robust assertions for watcher execution (#76977)
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 12dda6f commit c605cdf

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.util.Locale;
4646
import java.util.Map;
4747
import java.util.concurrent.TimeUnit;
48+
import java.util.concurrent.atomic.AtomicBoolean;
4849
import java.util.stream.Collectors;
4950

5051
import static org.elasticsearch.core.TimeValue.timeValueSeconds;
@@ -53,7 +54,6 @@
5354
import static org.hamcrest.Matchers.containsString;
5455
import static org.hamcrest.Matchers.equalTo;
5556
import static org.hamcrest.Matchers.everyItem;
56-
import static org.hamcrest.Matchers.greaterThan;
5757
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
5858
import static org.hamcrest.Matchers.hasEntry;
5959
import static org.hamcrest.Matchers.hasItems;
@@ -202,11 +202,9 @@ public void testWatcher() throws Exception {
202202
}
203203
}
204204

205-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/63088")
206205
@SuppressWarnings("unchecked")
207206
public void testWatcherWithApiKey() throws Exception {
208207
final Request getWatchStatusRequest = new Request("GET", "/_watcher/watch/watch_with_api_key");
209-
getWatchStatusRequest.addParameter("filter_path", "status");
210208

211209
if (isRunningAgainstOldCluster()) {
212210
final Request createApiKeyRequest = new Request("PUT", "/_security/api_key");
@@ -247,11 +245,19 @@ public void testWatcherWithApiKey() throws Exception {
247245
final Map<String, Object> status = (Map<String, Object>) getWatchStatusResponse.get("status");
248246
final int version = (int) status.get("version");
249247

248+
final AtomicBoolean versionIncreased = new AtomicBoolean();
249+
final AtomicBoolean executed = new AtomicBoolean();
250250
assertBusy(() -> {
251251
final Map<String, Object> newGetWatchStatusResponse = entityAsMap(client().performRequest(getWatchStatusRequest));
252252
final Map<String, Object> newStatus = (Map<String, Object>) newGetWatchStatusResponse.get("status");
253-
assertThat((int) newStatus.get("version"), greaterThan(version + 2));
254-
assertEquals("executed", newStatus.get("execution_state"));
253+
if (false == versionIncreased.get() && version < (int) newStatus.get("version")) {
254+
versionIncreased.set(true);
255+
}
256+
if (false == executed.get() && "executed".equals(newStatus.get("execution_state"))) {
257+
executed.set(true);
258+
}
259+
assertThat("version increased: [" + versionIncreased.get() + "], executed: [" + executed.get() + "]",
260+
versionIncreased.get() && executed.get(), is(true));
255261
});
256262
} finally {
257263
stopWatcher();

0 commit comments

Comments
 (0)