Tests: Fix watcher test using DNS resolution (elastic/elasticsearch#4576)

Turns out that this test became flaky on dev machines with specific DNS setup.
This test uses an index action to provoke an error, thus there is no dependency
on anything network specific.

The reason it was uncovered now, was due to the change to the Apache HTTP client which is doing DNS lookups. This DNS lookup happened inadvertantly because of a bug in the test, which had a URI like http://http://127.0.0.1.... However having web request was not needed at all, so it was replaced.

Closes elastic/elasticsearch#4561

Original commit: elastic/x-pack-elasticsearch@158516b5e5
This commit is contained in:
Alexander Reelsen 2017-01-10 17:26:54 +01:00 committed by GitHub
parent a890cfb81e
commit 56e3e107d4
1 changed files with 17 additions and 4 deletions

View File

@ -7,6 +7,7 @@ package org.elasticsearch.xpack.watcher.actions.throttler;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.xpack.common.http.HttpMethod; import org.elasticsearch.xpack.common.http.HttpMethod;
import org.elasticsearch.xpack.common.http.HttpRequestTemplate; import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
import org.elasticsearch.xpack.common.text.TextTemplate; import org.elasticsearch.xpack.common.text.TextTemplate;
@ -40,8 +41,8 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.indexAction;
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction; import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.webhookAction;
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder; import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule; import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval; import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
@ -287,8 +288,21 @@ public class ActionThrottleTests extends AbstractWatcherIntegrationTestCase {
}, 20, TimeUnit.SECONDS); }, 20, TimeUnit.SECONDS);
} }
@AwaitsFix(bugUrl = "https://github.com/elastic/x-pack/issues/4561")
public void testFailingActionDoesGetThrottled() throws Exception { public void testFailingActionDoesGetThrottled() throws Exception {
// create a mapping with a wrong @timestamp field, so that the index action of the watch below will fail
String mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject("bar")
.startObject("properties")
.startObject("@timestamp")
.field("type", "integer")
.endObject()
.endObject()
.endObject()
.endObject().string();
client().admin().indices().prepareCreate("foo").addMapping("bar", mapping).get();
TimeValue throttlePeriod = new TimeValue(60, TimeUnit.MINUTES); TimeValue throttlePeriod = new TimeValue(60, TimeUnit.MINUTES);
watcherClient().preparePutWatch("_id").setSource(watchBuilder() watcherClient().preparePutWatch("_id").setSource(watchBuilder()
@ -296,8 +310,7 @@ public class ActionThrottleTests extends AbstractWatcherIntegrationTestCase {
new IntervalSchedule.Interval(60, IntervalSchedule.Interval.Unit.MINUTES)))) new IntervalSchedule.Interval(60, IntervalSchedule.Interval.Unit.MINUTES))))
.defaultThrottlePeriod(throttlePeriod) .defaultThrottlePeriod(throttlePeriod)
.addAction("logging", loggingAction("test out")) .addAction("logging", loggingAction("test out"))
// no DNS resolution here please .addAction("failing_hook", indexAction("foo", "bar").setExecutionTimeField("@timestamp")))
.addAction("failing_hook", webhookAction(HttpRequestTemplate.builder("http://127.0.0.1/foobar", 80))))
.get(); .get();
refresh(Watch.INDEX); refresh(Watch.INDEX);