Skip to content

Commit 7269d35

Browse files
Fix ThreadPoolMergeExecutorServiceDiskSpaceTests testAvailableDiskSpaceMonitorWhenFileSystemStatErrors (#130025) (#130117)
The test method needs to distinguish between the available disk space update values, when they are coming from either FS. So the update values from the 2 FSs mustn't be equal. Fixes #129149
1 parent 2d16a97 commit 7269d35

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

server/src/test/java/org/elasticsearch/index/engine/ThreadPoolMergeExecutorServiceDiskSpaceTests.java

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,19 @@ public void testDiskSpaceMonitorStartsAsDisabled() throws Exception {
324324
}
325325

326326
public void testAvailableDiskSpaceMonitorWhenFileSystemStatErrors() throws Exception {
327-
aFileStore.usableSpace = randomLongBetween(1L, 100L);
328-
aFileStore.totalSpace = randomLongBetween(1L, 100L);
329-
bFileStore.usableSpace = randomLongBetween(1L, 100L);
330-
bFileStore.totalSpace = randomLongBetween(1L, 100L);
327+
long aUsableSpace;
328+
long bUsableSpace;
329+
do {
330+
aFileStore.usableSpace = randomLongBetween(1L, 1000L);
331+
aFileStore.totalSpace = randomLongBetween(1L, 1000L);
332+
bFileStore.usableSpace = randomLongBetween(1L, 1000L);
333+
bFileStore.totalSpace = randomLongBetween(1L, 1000L);
334+
// the default 5% (same as flood stage level)
335+
aUsableSpace = Math.max(aFileStore.usableSpace - aFileStore.totalSpace / 20, 0L);
336+
bUsableSpace = Math.max(bFileStore.usableSpace - bFileStore.totalSpace / 20, 0L);
337+
} while (aUsableSpace == bUsableSpace); // they must be different in order to distinguish the available disk space updates
338+
long finalBUsableSpace = bUsableSpace;
339+
long finalAUsableSpace = aUsableSpace;
331340
boolean aErrorsFirst = randomBoolean();
332341
if (aErrorsFirst) {
333342
// the "a" file system will error when collecting stats
@@ -355,18 +364,10 @@ public void testAvailableDiskSpaceMonitorWhenFileSystemStatErrors() throws Excep
355364
assertThat(availableDiskSpaceUpdates.size(), is(1));
356365
if (aErrorsFirst) {
357366
// uses the stats from "b"
358-
assertThat(
359-
getLast(availableDiskSpaceUpdates).getBytes(),
360-
// the default 5% (same as flood stage level)
361-
is(Math.max(bFileStore.usableSpace - bFileStore.totalSpace / 20, 0L))
362-
);
367+
assertThat(getLast(availableDiskSpaceUpdates).getBytes(), is(finalBUsableSpace));
363368
} else {
364369
// uses the stats from "a"
365-
assertThat(
366-
getLast(availableDiskSpaceUpdates).getBytes(),
367-
// the default 5% (same as flood stage level)
368-
is(Math.max(aFileStore.usableSpace - aFileStore.totalSpace / 20, 0L))
369-
);
370+
assertThat(getLast(availableDiskSpaceUpdates).getBytes(), is(finalAUsableSpace));
370371
}
371372
}
372373
});
@@ -393,21 +394,14 @@ public void testAvailableDiskSpaceMonitorWhenFileSystemStatErrors() throws Excep
393394
}
394395
assertBusy(() -> {
395396
synchronized (availableDiskSpaceUpdates) {
397+
// the updates are different values
396398
assertThat(availableDiskSpaceUpdates.size(), is(3));
397399
if (aErrorsFirst) {
398400
// uses the stats from "a"
399-
assertThat(
400-
getLast(availableDiskSpaceUpdates).getBytes(),
401-
// the default 5% (same as flood stage level)
402-
is(Math.max(aFileStore.usableSpace - aFileStore.totalSpace / 20, 0L))
403-
);
401+
assertThat(getLast(availableDiskSpaceUpdates).getBytes(), is(finalAUsableSpace));
404402
} else {
405403
// uses the stats from "b"
406-
assertThat(
407-
getLast(availableDiskSpaceUpdates).getBytes(),
408-
// the default 5% (same as flood stage level)
409-
is(Math.max(bFileStore.usableSpace - bFileStore.totalSpace / 20, 0L))
410-
);
404+
assertThat(getLast(availableDiskSpaceUpdates).getBytes(), is(finalBUsableSpace));
411405
}
412406
}
413407
});

0 commit comments

Comments
 (0)