Skip to content

Commit a045bf0

Browse files
jakelandisastefan
authored andcommitted
Watcher fix ActivateWatchTests (elastic#82157)
This commit attempts to fix a set of Watcher tests that can fail due to unexpected execution of Watches after Watcher has been stopped. The theory here is that a Watch can be queued but not fully executed then Watcher is shutdown, the test does some clean up, then the queued Watch finishes execution and causes some some additional cleanup to fail. The change here ensures that when Watcher is stopped from AbstractWatcherIntegrationTestCase that it will also wait until there are no more current Watches executing. closes elastic#66495
1 parent 8c17478 commit a045bf0

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

x-pack/plugin/watcher/src/internalClusterTest/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,8 @@ protected void ensureLicenseEnabled() throws Exception {
567567

568568
protected void stopWatcher() throws Exception {
569569
assertBusy(() -> {
570-
WatcherStatsResponse watcherStatsResponse = new WatcherStatsRequestBuilder(client()).get();
570+
571+
WatcherStatsResponse watcherStatsResponse = new WatcherStatsRequestBuilder(client()).setIncludeCurrentWatches(true).get();
571572
assertThat(watcherStatsResponse.hasFailures(), is(false));
572573
List<Tuple<String, WatcherState>> currentStatesFromStatsRequest = watcherStatsResponse.getNodes()
573574
.stream()
@@ -580,7 +581,8 @@ protected void stopWatcher() throws Exception {
580581
.collect(Collectors.toList());
581582
List<WatcherState> states = currentStatesFromStatsRequest.stream().map(Tuple::v2).collect(Collectors.toList());
582583

583-
logger.info("waiting to stop watcher, current states {}", currentStatesFromStatsRequest);
584+
long currentWatches = watcherStatsResponse.getNodes().stream().mapToLong(n -> n.getSnapshots().size()).sum();
585+
logger.info("waiting to stop watcher, current states {}, current watches [{}]", currentStatesFromStatsRequest, currentWatches);
584586

585587
boolean isAllStateStarted = states.stream().allMatch(w -> w == WatcherState.STARTED);
586588
if (isAllStateStarted) {
@@ -594,7 +596,7 @@ protected void stopWatcher() throws Exception {
594596
}
595597

596598
boolean isAllStateStopped = states.stream().allMatch(w -> w == WatcherState.STOPPED);
597-
if (isAllStateStopped) {
599+
if (isAllStateStopped && currentWatches == 0) {
598600
return;
599601
}
600602

x-pack/plugin/watcher/src/internalClusterTest/java/org/elasticsearch/xpack/watcher/transport/action/activate/ActivateWatchTests.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ protected boolean timeWarped() {
5050
return false;
5151
}
5252

53-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/66495")
5453
public void testDeactivateAndActivate() throws Exception {
5554
PutWatchResponse putWatchResponse = new PutWatchRequestBuilder(client()).setId("_id")
5655
.setSource(
@@ -107,7 +106,6 @@ public void testDeactivateAndActivate() throws Exception {
107106
});
108107
}
109108

110-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/66495")
111109
public void testLoadWatchWithoutAState() throws Exception {
112110
PutWatchResponse putWatchResponse = new PutWatchRequestBuilder(client()).setId("_id")
113111
.setSource(

0 commit comments

Comments
 (0)