Skip to content

Commit

Permalink
Add extra steps to ensure that watch indices are created before test …
Browse files Browse the repository at this point in the history
…starts (#66416) (#66422)

This PR updates the initialization logic in TransportMonitoringMigrateAlertsActionTests to wait
for the watch indices separately from the rest of the initialization logic in order to allow for the
.watches index to be available before the test begins.
  • Loading branch information
jbaiera authored Dec 16, 2020
1 parent 0297612 commit a074cf9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchAction;
import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchRequest;
import org.elasticsearch.xpack.monitoring.LocalStateMonitoring;
import org.elasticsearch.xpack.core.watcher.watch.Watch;
import org.elasticsearch.xpack.monitoring.Monitoring;
import org.elasticsearch.xpack.monitoring.MonitoringService;
import org.elasticsearch.xpack.monitoring.exporter.ClusterAlertsUtil;
Expand Down Expand Up @@ -135,12 +136,7 @@ public void testLocalAlertsRemoval() throws Exception {
assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(exporterSettings));

// ensure resources exist
assertBusy(() -> {
assertThat(indexExists(".monitoring-*"), is(true));
ensureYellowAndNoInitializingShards(".monitoring-*");
checkMonitoringTemplates();
assertWatchesExist(true);
});
ensureInitialLocalResources();

// call migration api
MonitoringMigrateAlertsResponse response = client().execute(MonitoringMigrateAlertsAction.INSTANCE,
Expand Down Expand Up @@ -174,12 +170,7 @@ public void testRepeatedLocalAlertsRemoval() throws Exception {
assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(exporterSettings));

// ensure resources exist
assertBusy(() -> {
assertThat(indexExists(".monitoring-*"), is(true));
ensureYellowAndNoInitializingShards(".monitoring-*");
checkMonitoringTemplates();
assertWatchesExist(true);
});
ensureInitialLocalResources();

// call migration api
MonitoringMigrateAlertsResponse response = client().execute(MonitoringMigrateAlertsAction.INSTANCE,
Expand Down Expand Up @@ -479,6 +470,7 @@ public void testRemoteAlertsRemoteDisallowsWatcher() throws Exception {
}

private void ensureInitialLocalResources() throws Exception {
waitForWatcherIndices();
assertBusy(() -> {
assertThat(indexExists(".monitoring-*"), is(true));
ensureYellowAndNoInitializingShards(".monitoring-*");
Expand Down Expand Up @@ -595,4 +587,9 @@ private void assertMonitorWatches(final MockWebServer webServer, final boolean r
}
}
}

protected void waitForWatcherIndices() throws Exception {
awaitIndexExists(Watch.INDEX);
assertBusy(() -> ensureYellowAndNoInitializingShards(Watch.INDEX));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ protected void waitForMonitoringIndices() throws Exception {
assertBusy(this::ensureMonitoringIndicesYellow);
}

private void awaitIndexExists(final String index) throws Exception {
protected void awaitIndexExists(final String index) throws Exception {
assertBusy(() -> assertIndicesExists(index), 30, TimeUnit.SECONDS);
}

Expand Down

0 comments on commit a074cf9

Please sign in to comment.