Skip to content

Commit 602cb62

Browse files
authored
Fix non-corruption in testCurrentHeaderVersion (#50883)
Today we make multiple attempts to corrupt the translog header in `TranslogHeaderTests#testCurrentHeaderVersion`, but if we are extraordinarily unlucky then this sequence of corruptions may restore the file to its original state. This change adjusts the test to only corrupt the file once, which is certain not to leave the file in its original state.
1 parent 4cecb7a commit 602cb62

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

server/src/test/java/org/elasticsearch/index/translog/TranslogHeaderTests.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,11 @@ public void testCurrentHeaderVersion() throws Exception {
5252
}
5353
final TranslogCorruptedException mismatchUUID = expectThrows(TranslogCorruptedException.class, () -> {
5454
try (FileChannel channel = FileChannel.open(translogFile, StandardOpenOption.READ)) {
55-
TranslogHeader.read(UUIDs.randomBase64UUID(), translogFile, channel);
55+
TranslogHeader.read(randomValueOtherThan(translogUUID, UUIDs::randomBase64UUID), translogFile, channel);
5656
}
5757
});
5858
assertThat(mismatchUUID.getMessage(), containsString("this translog file belongs to a different translog"));
59-
int corruptions = between(1, 10);
60-
for (int i = 0; i < corruptions && Files.size(translogFile) > 0; i++) {
61-
TestTranslog.corruptFile(logger, random(), translogFile, false);
62-
}
59+
TestTranslog.corruptFile(logger, random(), translogFile, false);
6360
final TranslogCorruptedException corruption = expectThrows(TranslogCorruptedException.class, () -> {
6461
try (FileChannel channel = FileChannel.open(translogFile, StandardOpenOption.READ)) {
6562
TranslogHeader.read(randomBoolean() ? outHeader.getTranslogUUID() : UUIDs.randomBase64UUID(), translogFile, channel);

0 commit comments

Comments
 (0)