Watcher: Improve assertion output in flaky test
The slack tests seem to fail periodically with not output This commit tries to add some more verbose output by making the query more broad and take failures into account to uncover, what happens in this test. Relates elastic/x-pack-elasticsearch#836 Original commit: elastic/x-pack-elasticsearch@e601b3a0df
This commit is contained in:
parent
f52760d2ac
commit
5b2351fad0
|
@ -22,8 +22,6 @@ import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encapsulates the xcontent source
|
* Encapsulates the xcontent source
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -9,6 +9,8 @@ import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
|
import org.elasticsearch.search.SearchHit;
|
||||||
import org.elasticsearch.test.junit.annotations.Network;
|
import org.elasticsearch.test.junit.annotations.Network;
|
||||||
import org.elasticsearch.xpack.notification.slack.SentMessages;
|
import org.elasticsearch.xpack.notification.slack.SentMessages;
|
||||||
import org.elasticsearch.xpack.notification.slack.SlackAccount;
|
import org.elasticsearch.xpack.notification.slack.SlackAccount;
|
||||||
|
@ -17,10 +19,13 @@ import org.elasticsearch.xpack.notification.slack.message.Attachment;
|
||||||
import org.elasticsearch.xpack.notification.slack.message.SlackMessage;
|
import org.elasticsearch.xpack.notification.slack.message.SlackMessage;
|
||||||
import org.elasticsearch.xpack.watcher.actions.slack.SlackAction;
|
import org.elasticsearch.xpack.watcher.actions.slack.SlackAction;
|
||||||
import org.elasticsearch.xpack.watcher.condition.AlwaysCondition;
|
import org.elasticsearch.xpack.watcher.condition.AlwaysCondition;
|
||||||
|
import org.elasticsearch.xpack.watcher.support.xcontent.XContentSource;
|
||||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||||
import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchResponse;
|
import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchResponse;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import static org.elasticsearch.common.xcontent.ToXContent.EMPTY_PARAMS;
|
import static org.elasticsearch.common.xcontent.ToXContent.EMPTY_PARAMS;
|
||||||
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
|
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
|
||||||
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
||||||
|
@ -113,11 +118,20 @@ public class SlackServiceTests extends AbstractWatcherIntegrationTestCase {
|
||||||
SearchResponse response = searchHistory(searchSource().query(boolQuery()
|
SearchResponse response = searchHistory(searchSource().query(boolQuery()
|
||||||
.must(termQuery("result.actions.id", "slack"))
|
.must(termQuery("result.actions.id", "slack"))
|
||||||
.must(termQuery("result.actions.type", "slack"))
|
.must(termQuery("result.actions.type", "slack"))
|
||||||
.must(termQuery("result.actions.status", "success"))
|
.must(termQuery("result.actions.slack.account", account))));
|
||||||
.must(termQuery("result.actions.slack.account", account))
|
|
||||||
.must(termQuery("result.actions.slack.sent_messages.status", "success"))));
|
|
||||||
|
|
||||||
assertThat(response, notNullValue());
|
|
||||||
assertThat(response.getHits().getTotalHits(), is(1L));
|
assertThat(response.getHits().getTotalHits(), is(1L));
|
||||||
|
|
||||||
|
SearchHit hit = response.getHits().getAt(0);
|
||||||
|
assertSuccess(hit, "result.actions.0.slack.sent_messages.0.status");
|
||||||
|
assertSuccess(hit, "result.actions.0.slack.sent_messages.1.status");
|
||||||
|
assertSuccess(hit, "result.actions.0.status");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertSuccess(SearchHit hit, String path) {
|
||||||
|
XContentSource source = new XContentSource(hit.getSourceRef(), XContentType.JSON);
|
||||||
|
String json = hit.getSourceAsString();
|
||||||
|
String message = String.format(Locale.ROOT, "Expected path [%s] to be [success], json is %s", path, json);
|
||||||
|
assertThat(message, source.getValue(path), is("success"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue