From b1b28ba941e07a711fc818b975218d929a774e74 Mon Sep 17 00:00:00 2001 From: Daniel Mitterdorfer Date: Thu, 12 Oct 2023 16:29:06 +0200 Subject: [PATCH] Don't test broken index templates (#100745) So far we've tested in the index template registry tests for Universal Profiling what happens on outdated resources. However, the test not only tested for outdated index templates but also for completely broken ones, i.e. that the version property is missing. That cannot happen in practice because the plugin itself controls installation of index templates where the `version` property is always present. Hence, we don't test for this case anymore. Closes #99943 --- .../ProfilingIndexTemplateRegistryTests.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/ProfilingIndexTemplateRegistryTests.java b/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/ProfilingIndexTemplateRegistryTests.java index a5a2ee7d89768..b0de50cac8b5b 100644 --- a/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/ProfilingIndexTemplateRegistryTests.java +++ b/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/ProfilingIndexTemplateRegistryTests.java @@ -316,21 +316,18 @@ public void testAllResourcesPresentButOutdated() { Map composableTemplates = new HashMap<>(); Map policies = new HashMap<>(); for (String templateName : registry.getComponentTemplateConfigs().keySet()) { - // outdated (or missing) version - componentTemplates.put(templateName, frequently() ? ProfilingIndexTemplateRegistry.INDEX_TEMPLATE_VERSION - 1 : null); + // outdated version + componentTemplates.put(templateName, randomIntBetween(1, ProfilingIndexTemplateRegistry.INDEX_TEMPLATE_VERSION - 1)); } for (String templateName : registry.getComposableTemplateConfigs().keySet()) { - // outdated (or missing) version - composableTemplates.put(templateName, frequently() ? ProfilingIndexTemplateRegistry.INDEX_TEMPLATE_VERSION - 1 : null); + // outdated version + composableTemplates.put(templateName, randomIntBetween(1, ProfilingIndexTemplateRegistry.INDEX_TEMPLATE_VERSION - 1)); } for (LifecyclePolicy policy : registry.getLifecyclePolicies()) { // make a copy as we're modifying the version mapping Map metadata = new HashMap<>(policy.getMetadata()); - if (frequently()) { - metadata.put("version", ProfilingIndexTemplateRegistry.INDEX_TEMPLATE_VERSION - 1); - } else { - metadata.remove("version"); - } + // outdated version + metadata.put("version", randomIntBetween(1, ProfilingIndexTemplateRegistry.INDEX_TEMPLATE_VERSION - 1)); policies.put(policy.getName(), new LifecyclePolicy(policy.getName(), policy.getPhases(), metadata)); } ClusterState clusterState = createClusterState(Settings.EMPTY, componentTemplates, composableTemplates, policies, nodes);