Skip to content

Commit cb13447

Browse files
authored
[TEST] Fix MlMappingsUpgradeIT testMappingsUpgrade (#37769)
Made the test tolerant to index upgrade being run in between the old/mixed/upgraded portions. This can occur because the rolling upgrade tests all share the same indices. Fixes #37763
1 parent 780b4c7 commit cb13447

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/MlMappingsUpgradeIT.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ protected Collection<String> templatesToWaitFor() {
3838
* The purpose of this test is to ensure that when a job is open through a rolling upgrade we upgrade the results
3939
* index mappings when it is assigned to an upgraded node even if no other ML endpoint is called after the upgrade
4040
*/
41-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/37763")
4241
public void testMappingsUpgrade() throws Exception {
4342

4443
switch (CLUSTER_TYPE) {
@@ -65,6 +64,8 @@ private void createAndOpenTestJob() throws IOException {
6564
Job.Builder job = new Job.Builder(JOB_ID);
6665
job.setAnalysisConfig(analysisConfig);
6766
job.setDataDescription(new DataDescription.Builder());
67+
// Use a custom index because other rolling upgrade tests meddle with the shared index
68+
job.setResultsIndexName("mappings-upgrade-test");
6869

6970
Request putJob = new Request("PUT", "_ml/anomaly_detectors/" + JOB_ID);
7071
putJob.setJsonEntity(Strings.toString(job.build()));
@@ -85,7 +86,16 @@ private void assertUpgradedMappings() throws Exception {
8586

8687
Map<String, Object> responseLevel = entityAsMap(response);
8788
assertNotNull(responseLevel);
88-
Map<String, Object> indexLevel = (Map<String, Object>) responseLevel.get(".ml-anomalies-shared");
89+
Map<String, Object> indexLevel = null;
90+
// The name of the concrete index underlying the results index alias may or may not have been changed
91+
// by the upgrade process (depending on what other tests are being run and the order they're run in),
92+
// so navigating to the next level of the tree must account for both cases
93+
for (Map.Entry<String, Object> entry : responseLevel.entrySet()) {
94+
if (entry.getKey().startsWith(".ml-anomalies-") && entry.getKey().contains("mappings-upgrade-test")) {
95+
indexLevel = (Map<String, Object>) entry.getValue();
96+
break;
97+
}
98+
}
8999
assertNotNull(indexLevel);
90100
Map<String, Object> mappingsLevel = (Map<String, Object>) indexLevel.get("mappings");
91101
assertNotNull(mappingsLevel);

0 commit comments

Comments
 (0)