Skip to content

Commit

Permalink
Waiting for watcher history index to be populated (#95643)
Browse files Browse the repository at this point in the history
  • Loading branch information
masseyke authored and pull[bot] committed Jul 10, 2023
1 parent 82be089 commit 4634324
Showing 1 changed file with 22 additions and 8 deletions.
Expand Up @@ -18,6 +18,7 @@
import org.elasticsearch.xpack.core.watcher.condition.Condition;
import org.elasticsearch.xpack.core.watcher.condition.ExecutableCondition;
import org.elasticsearch.xpack.core.watcher.execution.ExecutionState;
import org.elasticsearch.xpack.core.watcher.history.HistoryStoreField;
import org.elasticsearch.xpack.core.watcher.input.Input;
import org.elasticsearch.xpack.core.watcher.transport.actions.put.PutWatchRequestBuilder;
import org.elasticsearch.xpack.watcher.condition.CompareCondition;
Expand Down Expand Up @@ -92,7 +93,6 @@ protected Map<String, Function<Map<String, Object>, Object>> pluginScripts() {
/**
* A hard failure is where an exception is thrown by the script condition.
*/
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/94836")
@SuppressWarnings("unchecked")
public void testActionConditionWithHardFailures() throws Exception {
final String id = "testActionConditionWithHardFailures";
Expand All @@ -115,9 +115,14 @@ public void testActionConditionWithHardFailures() throws Exception {
assertWatchWithMinimumActionsCount(id, ExecutionState.EXECUTED, 1);

// only one action should have failed via condition
final SearchResponse response = searchHistory(SearchSourceBuilder.searchSource().query(termQuery("watch_id", id)));
assertThat(response.getHits().getTotalHits().value, is(oneOf(1L, 2L)));
assertBusy(() -> {
// Watcher history is now written asynchronously, so we check this in an assertBusy
ensureGreen(HistoryStoreField.DATA_STREAM);
final SearchResponse response = searchHistory(SearchSourceBuilder.searchSource().query(termQuery("watch_id", id)));
assertThat(response.getHits().getTotalHits().value, is(oneOf(1L, 2L)));
});

final SearchResponse response = searchHistory(SearchSourceBuilder.searchSource().query(termQuery("watch_id", id)));
final SearchHit hit = response.getHits().getAt(0);
final List<Object> actions = getActionsFromHit(hit.getSourceAsMap());

Expand All @@ -144,7 +149,6 @@ public void testActionConditionWithHardFailures() throws Exception {
}
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/94836")
@SuppressWarnings("unchecked")
public void testActionConditionWithFailures() throws Exception {
final String id = "testActionConditionWithFailures";
Expand All @@ -160,9 +164,14 @@ public void testActionConditionWithFailures() throws Exception {
assertWatchWithMinimumActionsCount(id, ExecutionState.EXECUTED, 1);

// only one action should have failed via condition
final SearchResponse response = searchHistory(SearchSourceBuilder.searchSource().query(termQuery("watch_id", id)));
assertThat(response.getHits().getTotalHits().value, is(oneOf(1L, 2L)));
assertBusy(() -> {
// Watcher history is now written asynchronously, so we check this in an assertBusy
ensureGreen(HistoryStoreField.DATA_STREAM);
final SearchResponse response = searchHistory(SearchSourceBuilder.searchSource().query(termQuery("watch_id", id)));
assertThat(response.getHits().getTotalHits().value, is(oneOf(1L, 2L)));
});

final SearchResponse response = searchHistory(SearchSourceBuilder.searchSource().query(termQuery("watch_id", id)));
final SearchHit hit = response.getHits().getAt(0);
final List<Object> actions = getActionsFromHit(hit.getSourceAsMap());

Expand All @@ -189,7 +198,6 @@ public void testActionConditionWithFailures() throws Exception {
}

@SuppressWarnings("unchecked")
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/65064")
public void testActionCondition() throws Exception {
final String id = "testActionCondition";
final List<ExecutableCondition> actionConditions = new ArrayList<>();
Expand All @@ -211,8 +219,14 @@ public void testActionCondition() throws Exception {
assertWatchWithMinimumActionsCount(id, ExecutionState.EXECUTED, 1);

// all actions should be successful
assertBusy(() -> {
// Watcher history is now written asynchronously, so we check this in an assertBusy
ensureGreen(HistoryStoreField.DATA_STREAM);
final SearchResponse response = searchHistory(SearchSourceBuilder.searchSource().query(termQuery("watch_id", id)));
assertThat(response.getHits().getTotalHits().value, is(oneOf(1L, 2L)));
});

final SearchResponse response = searchHistory(SearchSourceBuilder.searchSource().query(termQuery("watch_id", id)));
assertThat(response.getHits().getTotalHits().value, is(oneOf(1L, 2L)));

final SearchHit hit = response.getHits().getAt(0);
final List<Object> actions = getActionsFromHit(hit.getSourceAsMap());
Expand Down

0 comments on commit 4634324

Please sign in to comment.