Skip to content

Commit c64f4d1

Browse files
committed
Unmuted and adjusted smoke watcher test:
* Only return history docs with state equal to executed * Sort by execution time instead of triggered time. * Don't auto box to boolean to avoid potential NPE. * Throw AE instead of using fail() methods for better readability. * Reformated the search request body. Relates to #32299
1 parent a8c5be5 commit c64f4d1

File tree

1 file changed

+48
-15
lines changed

1 file changed

+48
-15
lines changed

x-pack/qa/smoke-test-watcher/src/test/java/org/elasticsearch/smoketest/SmokeTestWatcherTestSuiteIT.java

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.elasticsearch.common.settings.Settings;
1414
import org.elasticsearch.common.util.concurrent.ThreadContext;
1515
import org.elasticsearch.common.xcontent.XContentBuilder;
16+
import org.elasticsearch.common.xcontent.XContentType;
1617
import org.elasticsearch.test.rest.ESRestTestCase;
1718
import org.elasticsearch.test.rest.yaml.ObjectPath;
1819
import org.elasticsearch.xpack.test.rest.XPackRestTestConstants;
@@ -109,9 +110,8 @@ protected Settings restAdminSettings() {
109110
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build();
110111
}
111112

112-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/32299")
113113
public void testMonitorClusterHealth() throws Exception {
114-
String watchId = "cluster_health_watch";
114+
final String watchId = "cluster_health_watch";
115115

116116
// get master publish address
117117
Response clusterStateResponse = adminClient().performRequest(new Request("GET", "/_cluster/state"));
@@ -157,8 +157,9 @@ public void testMonitorClusterHealth() throws Exception {
157157

158158
// check watch history
159159
ObjectPath objectPath = getWatchHistoryEntry(watchId);
160-
boolean conditionMet = objectPath.evaluate("hits.hits.0._source.result.condition.met");
161-
assertThat(conditionMet, is(true));
160+
Boolean conditionMet = objectPath.evaluate("hits.hits.0._source.result.condition.met");
161+
String historyEntriesAsString = Strings.toString(objectPath.toXContentBuilder(XContentType.JSON.xContent()));
162+
assertThat("condition not met in response [" + historyEntriesAsString + "]", conditionMet, is(true));
162163

163164
deleteWatch(watchId);
164165
// Wrap inside an assertBusy(...), because watch may execute just after being deleted,
@@ -193,19 +194,51 @@ private ObjectPath getWatchHistoryEntry(String watchId) throws Exception {
193194
try {
194195
client().performRequest(new Request("POST", "/.watcher-history-*/_refresh"));
195196
} catch (ResponseException e) {
196-
final String err = "Failed to perform refresh of watcher history - " + e;
197-
logger.info(err);
198-
fail(err);
197+
final String err = "Failed to perform refresh of watcher history";
198+
logger.error(err, e);
199+
throw new AssertionError(err, e);
199200
}
200201

201202
try (XContentBuilder builder = jsonBuilder()) {
202203
builder.startObject();
203-
builder.startObject("query").startObject("bool").startArray("must");
204-
builder.startObject().startObject("term").startObject("watch_id").field("value", watchId).endObject().endObject()
205-
.endObject();
206-
builder.endArray().endObject().endObject();
207-
builder.startArray("sort").startObject().startObject("trigger_event.triggered_time").field("order", "desc").endObject()
208-
.endObject().endArray();
204+
{
205+
builder.startObject("query");
206+
{
207+
builder.startObject("bool");
208+
builder.startArray("must");
209+
builder.startObject();
210+
{
211+
builder.startObject("term");
212+
builder.startObject("watch_id");
213+
builder.field("value", watchId);
214+
builder.endObject();
215+
builder.endObject();
216+
}
217+
builder.endObject();
218+
builder.startObject();
219+
{
220+
builder.startObject("term");
221+
builder.startObject("state");
222+
builder.field("value", "executed");
223+
builder.endObject();
224+
builder.endObject();
225+
}
226+
builder.endObject();
227+
builder.endArray();
228+
builder.endObject();
229+
}
230+
builder.endObject();
231+
builder.startArray("sort");
232+
builder.startObject();
233+
{
234+
235+
builder.startObject("result.execution_time");
236+
builder.field("order", "desc");
237+
builder.endObject();
238+
}
239+
builder.endObject();
240+
builder.endArray();
241+
}
209242
builder.endObject();
210243

211244
logger.info("Searching watcher history");
@@ -223,8 +256,8 @@ private ObjectPath getWatchHistoryEntry(String watchId) throws Exception {
223256
objectPathReference.set(objectPath);
224257
} catch (ResponseException e) {
225258
final String err = "Failed to perform search of watcher history";
226-
logger.info(err, e);
227-
fail(err);
259+
logger.error(err, e);
260+
throw new AssertionError(err, e);
228261
}
229262
});
230263
return objectPathReference.get();

0 commit comments

Comments
 (0)