Skip to content

Commit

Permalink
Fix BuildTests serialization
Browse files Browse the repository at this point in the history
This commit fixes a randomization bug in the tests for Build
serialization, which could generate the same object when it should
mutate.

closes elastic#85800
  • Loading branch information
rjernst committed Apr 12, 2022
1 parent d60cde6 commit baca7db
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions server/src/test/java/org/elasticsearch/BuildTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,8 @@ public void testSerialization() {
// Note: the cast of the Copy- and MutateFunction is needed for some IDE (specifically Eclipse 4.10.0) to infer the right type
(WriteableBuild b) -> copyWriteable(b, writableRegistry(), WriteableBuild::new, Version.CURRENT),
(WriteableBuild b) -> {
switch (randomIntBetween(1, 6)) {
switch (randomIntBetween(1, 5)) {
case 1:
return new WriteableBuild(
new Build(b.build.type(), b.build.hash(), b.build.date(), b.build.isSnapshot(), b.build.qualifiedVersion())
);
case 2:
return new WriteableBuild(
new Build(
randomValueOtherThan(b.build.type(), () -> randomFrom(Build.Type.values())),
Expand All @@ -163,7 +159,7 @@ public void testSerialization() {
b.build.qualifiedVersion()
)
);
case 3:
case 2:
return new WriteableBuild(
new Build(
b.build.type(),
Expand All @@ -173,7 +169,7 @@ public void testSerialization() {
b.build.qualifiedVersion()
)
);
case 4:
case 3:
return new WriteableBuild(
new Build(
b.build.type(),
Expand All @@ -183,7 +179,7 @@ public void testSerialization() {
b.build.qualifiedVersion()
)
);
case 5:
case 4:
return new WriteableBuild(
new Build(
b.build.type(),
Expand All @@ -193,7 +189,7 @@ public void testSerialization() {
b.build.qualifiedVersion()
)
);
case 6:
case 5:
return new WriteableBuild(
new Build(
b.build.type(),
Expand Down

0 comments on commit baca7db

Please sign in to comment.