Skip to content

Commit c9cd106

Browse files
committed
Fix tests in SetSingleNodeAllocateStepTests (elastic#135724)
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. Instead, we should get a random version that is at most the previous version, to guarantee that `oldVersion` always precedes the current version. Fixes elastic#135590 (cherry picked from commit 712cf9f)
1 parent c6fe3a6 commit c9cd106

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SetSingleNodeAllocateStepTests.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.elasticsearch.common.settings.Settings.Builder;
3030
import org.elasticsearch.common.transport.TransportAddress;
3131
import org.elasticsearch.common.util.Maps;
32+
import org.elasticsearch.env.BuildVersion;
3233
import org.elasticsearch.index.Index;
3334
import org.elasticsearch.index.IndexNotFoundException;
3435
import org.elasticsearch.index.IndexVersion;
@@ -394,11 +395,7 @@ public void testPerformActionAttrsNoShard() {
394395
}
395396

396397
public void testPerformActionSomeShardsOnlyOnNewNodes() throws Exception {
397-
VersionInformation oldVersion = new VersionInformation(
398-
VersionUtils.randomCompatibleVersion(random(), VersionUtils.getPreviousVersion()),
399-
IndexVersions.MINIMUM_COMPATIBLE,
400-
IndexVersionUtils.randomCompatibleVersion(random())
401-
);
398+
final VersionInformation oldVersion = randomOldVersionInformation();
402399
final int numNodes = randomIntBetween(2, 20); // Need at least 2 nodes to have some nodes on a new version
403400
final int numNewNodes = randomIntBetween(1, numNodes - 1);
404401
final int numOldNodes = numNodes - numNewNodes;
@@ -459,11 +456,7 @@ public void testPerformActionSomeShardsOnlyOnNewNodes() throws Exception {
459456
}
460457

461458
public void testPerformActionSomeShardsOnlyOnNewNodesButNewNodesInvalidAttrs() {
462-
VersionInformation oldVersion = new VersionInformation(
463-
VersionUtils.randomCompatibleVersion(random(), VersionUtils.getPreviousVersion()),
464-
IndexVersions.MINIMUM_COMPATIBLE,
465-
IndexVersionUtils.randomCompatibleVersion(random())
466-
);
459+
final var oldVersion = randomOldVersionInformation();
467460
final int numNodes = randomIntBetween(2, 20); // Need at least 2 nodes to have some nodes on a new version
468461
final int numNewNodes = randomIntBetween(1, numNodes - 1);
469462
final int numOldNodes = numNodes - numNewNodes;
@@ -532,11 +525,7 @@ public void testPerformActionSomeShardsOnlyOnNewNodesButNewNodesInvalidAttrs() {
532525
}
533526

534527
public void testPerformActionNewShardsExistButWithInvalidAttributes() throws Exception {
535-
VersionInformation oldVersion = new VersionInformation(
536-
VersionUtils.randomCompatibleVersion(random(), VersionUtils.getPreviousVersion()),
537-
IndexVersions.MINIMUM_COMPATIBLE,
538-
IndexVersionUtils.randomCompatibleVersion(random())
539-
);
528+
final VersionInformation oldVersion = randomOldVersionInformation();
540529
final int numNodes = randomIntBetween(2, 20); // Need at least 2 nodes to have some nodes on a new version
541530
final int numNewNodes = randomIntBetween(1, numNodes - 1);
542531
final int numOldNodes = numNodes - numNewNodes;
@@ -604,6 +593,18 @@ public void testPerformActionNewShardsExistButWithInvalidAttributes() throws Exc
604593
assertNodeSelected(indexMetadata, indexMetadata.getIndex(), oldNodeIds, discoveryNodes, indexRoutingTable.build());
605594
}
606595

596+
private VersionInformation randomOldVersionInformation() {
597+
final var previousVersion = VersionUtils.getPreviousVersion();
598+
final var version = VersionUtils.randomVersionBetween(random(), previousVersion.minimumCompatibilityVersion(), previousVersion);
599+
return new VersionInformation(
600+
BuildVersion.fromVersionId(version.id()),
601+
version,
602+
IndexVersions.MINIMUM_COMPATIBLE,
603+
IndexVersions.MINIMUM_COMPATIBLE,
604+
IndexVersionUtils.randomCompatibleVersion(random())
605+
);
606+
}
607+
607608
private Collection<Map.Entry<String, String>> generateRandomValidAttributes(int numAttrs) {
608609
return generateRandomValidAttributes(numAttrs, "");
609610
}

0 commit comments

Comments
 (0)