From 541e0ed2432d581e51859024c4ac2b3e6d37755b Mon Sep 17 00:00:00 2001 From: Niels Bauman Date: Tue, 30 Sep 2025 16:40:53 -0300 Subject: [PATCH] Fix tests in `SetSingleNodeAllocateStepTests` By doing `VersionUtils.randomCompatibleVersion(random(), VersionUtils.getPreviousVersion())`, we could also get `Version.CURRENT`, as that version is also compatible with the previous version (unless we're running right after a major version was released). If the `oldVersion` variable in these tests is equal to the current version, the tests will fail as their whole goal is to verify behavior with different node versions. Fixes #135590 --- .../ilm/SetSingleNodeAllocateStepTests.java | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SetSingleNodeAllocateStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SetSingleNodeAllocateStepTests.java index 9f105361b97c1..67b20f35da7c7 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SetSingleNodeAllocateStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SetSingleNodeAllocateStepTests.java @@ -29,6 +29,7 @@ import org.elasticsearch.common.settings.Settings.Builder; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.util.Maps; +import org.elasticsearch.env.BuildVersion; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexVersion; @@ -394,11 +395,7 @@ public void testPerformActionAttrsNoShard() { } public void testPerformActionSomeShardsOnlyOnNewNodes() throws Exception { - VersionInformation oldVersion = new VersionInformation( - VersionUtils.randomCompatibleVersion(random(), VersionUtils.getPreviousVersion()), - IndexVersions.MINIMUM_COMPATIBLE, - IndexVersionUtils.randomCompatibleVersion(random()) - ); + final VersionInformation oldVersion = randomOldVersionInformation(); final int numNodes = randomIntBetween(2, 20); // Need at least 2 nodes to have some nodes on a new version final int numNewNodes = randomIntBetween(1, numNodes - 1); final int numOldNodes = numNodes - numNewNodes; @@ -459,11 +456,7 @@ public void testPerformActionSomeShardsOnlyOnNewNodes() throws Exception { } public void testPerformActionSomeShardsOnlyOnNewNodesButNewNodesInvalidAttrs() { - VersionInformation oldVersion = new VersionInformation( - VersionUtils.randomCompatibleVersion(random(), VersionUtils.getPreviousVersion()), - IndexVersions.MINIMUM_COMPATIBLE, - IndexVersionUtils.randomCompatibleVersion(random()) - ); + final var oldVersion = randomOldVersionInformation(); final int numNodes = randomIntBetween(2, 20); // Need at least 2 nodes to have some nodes on a new version final int numNewNodes = randomIntBetween(1, numNodes - 1); final int numOldNodes = numNodes - numNewNodes; @@ -532,11 +525,7 @@ public void testPerformActionSomeShardsOnlyOnNewNodesButNewNodesInvalidAttrs() { } public void testPerformActionNewShardsExistButWithInvalidAttributes() throws Exception { - VersionInformation oldVersion = new VersionInformation( - VersionUtils.randomCompatibleVersion(random(), VersionUtils.getPreviousVersion()), - IndexVersions.MINIMUM_COMPATIBLE, - IndexVersionUtils.randomCompatibleVersion(random()) - ); + final VersionInformation oldVersion = randomOldVersionInformation(); final int numNodes = randomIntBetween(2, 20); // Need at least 2 nodes to have some nodes on a new version final int numNewNodes = randomIntBetween(1, numNodes - 1); final int numOldNodes = numNodes - numNewNodes; @@ -604,6 +593,18 @@ public void testPerformActionNewShardsExistButWithInvalidAttributes() throws Exc assertNodeSelected(indexMetadata, indexMetadata.getIndex(), oldNodeIds, discoveryNodes, indexRoutingTable.build()); } + private VersionInformation randomOldVersionInformation() { + final var previousVersion = VersionUtils.getPreviousVersion(); + final var version = VersionUtils.randomVersionBetween(random(), previousVersion.minimumCompatibilityVersion(), previousVersion); + return new VersionInformation( + BuildVersion.fromVersionId(version.id()), + version, + IndexVersions.MINIMUM_COMPATIBLE, + IndexVersions.MINIMUM_COMPATIBLE, + IndexVersionUtils.randomCompatibleVersion(random()) + ); + } + private Collection> generateRandomValidAttributes(int numAttrs) { return generateRandomValidAttributes(numAttrs, ""); }