Skip to content

Commit c729187

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 157d66a commit c729187

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
@@ -26,6 +26,7 @@
2626
import org.elasticsearch.common.settings.Settings.Builder;
2727
import org.elasticsearch.common.transport.TransportAddress;
2828
import org.elasticsearch.common.util.Maps;
29+
import org.elasticsearch.env.BuildVersion;
2930
import org.elasticsearch.index.Index;
3031
import org.elasticsearch.index.IndexNotFoundException;
3132
import org.elasticsearch.index.IndexVersion;
@@ -386,11 +387,7 @@ public void testPerformActionAttrsNoShard() {
386387
}
387388

388389
public void testPerformActionSomeShardsOnlyOnNewNodes() throws Exception {
389-
VersionInformation oldVersion = new VersionInformation(
390-
VersionUtils.randomCompatibleVersion(random(), VersionUtils.getPreviousVersion()),
391-
IndexVersions.MINIMUM_COMPATIBLE,
392-
IndexVersionUtils.randomCompatibleVersion(random())
393-
);
390+
final VersionInformation oldVersion = randomOldVersionInformation();
394391
final int numNodes = randomIntBetween(2, 20); // Need at least 2 nodes to have some nodes on a new version
395392
final int numNewNodes = randomIntBetween(1, numNodes - 1);
396393
final int numOldNodes = numNodes - numNewNodes;
@@ -451,11 +448,7 @@ public void testPerformActionSomeShardsOnlyOnNewNodes() throws Exception {
451448
}
452449

453450
public void testPerformActionSomeShardsOnlyOnNewNodesButNewNodesInvalidAttrs() {
454-
VersionInformation oldVersion = new VersionInformation(
455-
VersionUtils.randomCompatibleVersion(random(), VersionUtils.getPreviousVersion()),
456-
IndexVersions.MINIMUM_COMPATIBLE,
457-
IndexVersionUtils.randomCompatibleVersion(random())
458-
);
451+
final var oldVersion = randomOldVersionInformation();
459452
final int numNodes = randomIntBetween(2, 20); // Need at least 2 nodes to have some nodes on a new version
460453
final int numNewNodes = randomIntBetween(1, numNodes - 1);
461454
final int numOldNodes = numNodes - numNewNodes;
@@ -524,11 +517,7 @@ public void testPerformActionSomeShardsOnlyOnNewNodesButNewNodesInvalidAttrs() {
524517
}
525518

526519
public void testPerformActionNewShardsExistButWithInvalidAttributes() throws Exception {
527-
VersionInformation oldVersion = new VersionInformation(
528-
VersionUtils.randomCompatibleVersion(random(), VersionUtils.getPreviousVersion()),
529-
IndexVersions.MINIMUM_COMPATIBLE,
530-
IndexVersionUtils.randomCompatibleVersion(random())
531-
);
520+
final VersionInformation oldVersion = randomOldVersionInformation();
532521
final int numNodes = randomIntBetween(2, 20); // Need at least 2 nodes to have some nodes on a new version
533522
final int numNewNodes = randomIntBetween(1, numNodes - 1);
534523
final int numOldNodes = numNodes - numNewNodes;
@@ -596,6 +585,18 @@ public void testPerformActionNewShardsExistButWithInvalidAttributes() throws Exc
596585
assertNodeSelected(indexMetadata, indexMetadata.getIndex(), oldNodeIds, discoveryNodes, indexRoutingTable.build());
597586
}
598587

588+
private VersionInformation randomOldVersionInformation() {
589+
final var previousVersion = VersionUtils.getPreviousVersion();
590+
final var version = VersionUtils.randomVersionBetween(random(), previousVersion.minimumCompatibilityVersion(), previousVersion);
591+
return new VersionInformation(
592+
BuildVersion.fromVersionId(version.id()),
593+
version,
594+
IndexVersions.MINIMUM_COMPATIBLE,
595+
IndexVersions.MINIMUM_COMPATIBLE,
596+
IndexVersionUtils.randomCompatibleVersion(random())
597+
);
598+
}
599+
599600
private Collection<Map.Entry<String, String>> generateRandomValidAttributes(int numAttrs) {
600601
return generateRandomValidAttributes(numAttrs, "");
601602
}

0 commit comments

Comments
 (0)