From 6686323c2d80e92f86f81ce22c7c30f4440aa29c Mon Sep 17 00:00:00 2001 From: David Roberts Date: Wed, 23 Jan 2019 14:43:25 +0000 Subject: [PATCH] [TEST] Fix MlMappingsUpgradeIT testMappingsUpgrade 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 --- .../upgrades/MlMappingsUpgradeIT.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/MlMappingsUpgradeIT.java b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/MlMappingsUpgradeIT.java index ca41afe6c39da..4bded9a25c56c 100644 --- a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/MlMappingsUpgradeIT.java +++ b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/MlMappingsUpgradeIT.java @@ -38,7 +38,6 @@ protected Collection templatesToWaitFor() { * The purpose of this test is to ensure that when a job is open through a rolling upgrade we upgrade the results * index mappings when it is assigned to an upgraded node even if no other ML endpoint is called after the upgrade */ - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/37763") public void testMappingsUpgrade() throws Exception { switch (CLUSTER_TYPE) { @@ -65,6 +64,8 @@ private void createAndOpenTestJob() throws IOException { Job.Builder job = new Job.Builder(JOB_ID); job.setAnalysisConfig(analysisConfig); job.setDataDescription(new DataDescription.Builder()); + // Use a custom index because other rolling upgrade tests meddle with the shared index + job.setResultsIndexName("mappings-upgrade-test"); Request putJob = new Request("PUT", "_ml/anomaly_detectors/" + JOB_ID); putJob.setJsonEntity(Strings.toString(job.build())); @@ -85,7 +86,16 @@ private void assertUpgradedMappings() throws Exception { Map responseLevel = entityAsMap(response); assertNotNull(responseLevel); - Map indexLevel = (Map) responseLevel.get(".ml-anomalies-shared"); + Map indexLevel = null; + // The name of the concrete index underlying the results index alias may or may not have been changed + // by the upgrade process (depending on what other tests are being run and the order they're run in), + // so navigating to the next level of the tree must account for both cases + for (Map.Entry entry : responseLevel.entrySet()) { + if (entry.getKey().startsWith(".ml-anomalies-") && entry.getKey().contains("mappings-upgrade-test")) { + indexLevel = (Map) entry.getValue(); + break; + } + } assertNotNull(indexLevel); Map mappingsLevel = (Map) indexLevel.get("mappings"); assertNotNull(mappingsLevel);