Skip to content

Commit a074cf9

Browse files
authored
Add extra steps to ensure that watch indices are created before test 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.
1 parent 0297612 commit a074cf9

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/TransportMonitoringMigrateAlertsActionTests.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchAction;
3333
import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchRequest;
3434
import org.elasticsearch.xpack.monitoring.LocalStateMonitoring;
35+
import org.elasticsearch.xpack.core.watcher.watch.Watch;
3536
import org.elasticsearch.xpack.monitoring.Monitoring;
3637
import org.elasticsearch.xpack.monitoring.MonitoringService;
3738
import org.elasticsearch.xpack.monitoring.exporter.ClusterAlertsUtil;
@@ -135,12 +136,7 @@ public void testLocalAlertsRemoval() throws Exception {
135136
assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(exporterSettings));
136137

137138
// ensure resources exist
138-
assertBusy(() -> {
139-
assertThat(indexExists(".monitoring-*"), is(true));
140-
ensureYellowAndNoInitializingShards(".monitoring-*");
141-
checkMonitoringTemplates();
142-
assertWatchesExist(true);
143-
});
139+
ensureInitialLocalResources();
144140

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

176172
// ensure resources exist
177-
assertBusy(() -> {
178-
assertThat(indexExists(".monitoring-*"), is(true));
179-
ensureYellowAndNoInitializingShards(".monitoring-*");
180-
checkMonitoringTemplates();
181-
assertWatchesExist(true);
182-
});
173+
ensureInitialLocalResources();
183174

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

481472
private void ensureInitialLocalResources() throws Exception {
473+
waitForWatcherIndices();
482474
assertBusy(() -> {
483475
assertThat(indexExists(".monitoring-*"), is(true));
484476
ensureYellowAndNoInitializingShards(".monitoring-*");
@@ -595,4 +587,9 @@ private void assertMonitorWatches(final MockWebServer webServer, final boolean r
595587
}
596588
}
597589
}
590+
591+
protected void waitForWatcherIndices() throws Exception {
592+
awaitIndexExists(Watch.INDEX);
593+
assertBusy(() -> ensureYellowAndNoInitializingShards(Watch.INDEX));
594+
}
598595
}

x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/test/MonitoringIntegTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ protected void waitForMonitoringIndices() throws Exception {
200200
assertBusy(this::ensureMonitoringIndicesYellow);
201201
}
202202

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

0 commit comments

Comments
 (0)