Skip to content

Commit d2ace60

Browse files
nielsbaumanywangd
authored andcommitted
Fix IndexTemplateRegistryRolloverIT (elastic#127695)
My theory of why this test failed is that when we waited for the data stream to be marked for rollover, that condition was met on one of the nodes, causing us to index the documents to trigger the rollover, but the master node did not fully process the mark-for-rollover cluster state, resulting in the documents ending up in the first backing index. Therefore, we use `awaitClusterState` to wait for the data stream to be marked for rollover, which waits on the master node by default. Fixes elastic#127692
1 parent 66aa2b5 commit d2ace60

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,6 @@ tests:
435435
- class: org.elasticsearch.snapshots.SnapshotShutdownIT
436436
method: testSnapshotShutdownProgressTracker
437437
issue: https://github.com/elastic/elasticsearch/issues/127690
438-
- class: org.elasticsearch.xpack.core.template.IndexTemplateRegistryRolloverIT
439-
method: testRollover
440-
issue: https://github.com/elastic/elasticsearch/issues/127692
441438
- class: org.elasticsearch.backwards.MixedClusterClientYamlTestSuiteIT
442439
method: test {p0=search/350_point_in_time/point-in-time with index filter}
443440
issue: https://github.com/elastic/elasticsearch/issues/127741

x-pack/plugin/core/src/internalClusterTest/java/org/elasticsearch/xpack/core/template/IndexTemplateRegistryRolloverIT.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.cluster.ClusterChangedEvent;
1818
import org.elasticsearch.cluster.ClusterState;
1919
import org.elasticsearch.cluster.metadata.DataStream;
20+
import org.elasticsearch.cluster.metadata.ProjectId;
2021
import org.elasticsearch.cluster.project.TestProjectResolvers;
2122
import org.elasticsearch.cluster.service.ClusterService;
2223
import org.elasticsearch.datastreams.DataStreamsPlugin;
@@ -68,7 +69,8 @@ public void setup() {
6869
public void testRollover() throws Exception {
6970
ClusterState state = clusterService.state();
7071
registry.clusterChanged(new ClusterChangedEvent(IndexTemplateRegistryRolloverIT.class.getName(), state, state));
71-
assertBusy(() -> { assertTrue(clusterService.state().metadata().getProject().templatesV2().containsKey(TEST_INDEX_TEMPLATE_ID)); });
72+
final var projectId = ProjectId.DEFAULT;
73+
awaitClusterState(s -> s.metadata().getProject(projectId).templatesV2().containsKey(TEST_INDEX_TEMPLATE_ID));
7274
String dsName = TEST_INDEX_PATTERN.replace('*', '1');
7375
CreateDataStreamAction.Request createDataStreamRequest = new CreateDataStreamAction.Request(
7476
TEST_REQUEST_TIMEOUT,
@@ -80,7 +82,7 @@ public void testRollover() throws Exception {
8082
assertNumberOfBackingIndices(1);
8183
registry.incrementVersion();
8284
registry.clusterChanged(new ClusterChangedEvent(IndexTemplateRegistryRolloverIT.class.getName(), clusterService.state(), state));
83-
assertBusy(() -> assertTrue(getDataStream().rolloverOnWrite()));
85+
awaitClusterState(s -> s.metadata().getProject(projectId).dataStreams().get(dsName).rolloverOnWrite());
8486
assertNumberOfBackingIndices(1);
8587

8688
String timestampValue = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.formatMillis(System.currentTimeMillis());
@@ -89,7 +91,7 @@ public void testRollover() throws Exception {
8991
.source(String.format(Locale.ROOT, "{\"%s\":\"%s\"}", DEFAULT_TIMESTAMP_FIELD, timestampValue), XContentType.JSON)
9092
).actionGet();
9193
assertThat(docWriteResponse.status().getStatus(), equalTo(201));
92-
assertBusy(() -> assertNumberOfBackingIndices(2));
94+
awaitClusterState(s -> s.metadata().getProject(projectId).dataStreams().get(dsName).getIndices().size() == 2);
9395
}
9496

9597
private void assertNumberOfBackingIndices(final int expected) {

0 commit comments

Comments
 (0)