Skip to content

Commit 456de59

Browse files
committed
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 2e5e5fd commit 456de59

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,11 @@ public void testCurrentHeaderVersion() throws Exception {
5959
}
6060
final TranslogCorruptedException mismatchUUID = expectThrows(TranslogCorruptedException.class, () -> {
6161
try (FileChannel channel = FileChannel.open(translogFile, StandardOpenOption.READ)) {
62-
TranslogHeader.read(UUIDs.randomBase64UUID(), translogFile, channel);
62+
TranslogHeader.read(randomValueOtherThan(translogUUID, UUIDs::randomBase64UUID), translogFile, channel);
6363
}
6464
});
6565
assertThat(mismatchUUID.getMessage(), containsString("this translog file belongs to a different translog"));
66-
int corruptions = between(1, 10);
67-
for (int i = 0; i < corruptions && Files.size(translogFile) > 0; i++) {
68-
TestTranslog.corruptFile(logger, random(), translogFile, false);
69-
}
66+
TestTranslog.corruptFile(logger, random(), translogFile, false);
7067
final TranslogCorruptedException corruption = expectThrows(TranslogCorruptedException.class, () -> {
7168
try (FileChannel channel = FileChannel.open(translogFile, StandardOpenOption.READ)) {
7269
final TranslogHeader translogHeader = TranslogHeader.read(

0 commit comments

Comments
 (0)