Skip to content

Commit 70438d0

Browse files
Fix ThreadPoolMergeExecutorServiceDiskSpaceTests testAvailableDiskSpaceMonitorWhenFileSystemStatErrors (#130025) (#130113)
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 f71608f commit 70438d0

File tree

2 files changed

+18
-27
lines changed

2 files changed

+18
-27
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,6 @@ tests:
279279
- class: org.elasticsearch.packaging.test.DockerTests
280280
method: test010Install
281281
issue: https://github.com/elastic/elasticsearch/issues/125680
282-
- class: org.elasticsearch.index.engine.ThreadPoolMergeExecutorServiceDiskSpaceTests
283-
method: testAvailableDiskSpaceMonitorWhenFileSystemStatErrors
284-
issue: https://github.com/elastic/elasticsearch/issues/129149
285282
- class: org.elasticsearch.index.engine.ThreadPoolMergeExecutorServiceTests
286283
method: testIORateIsAdjustedForAllRunningMergeTasks
287284
issue: https://github.com/elastic/elasticsearch/issues/129531

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-
availableDiskSpaceUpdates.getLast().getBytes(),
360-
// the default 5% (same as flood stage level)
361-
is(Math.max(bFileStore.usableSpace - bFileStore.totalSpace / 20, 0L))
362-
);
367+
assertThat(availableDiskSpaceUpdates.getLast().getBytes(), is(finalBUsableSpace));
363368
} else {
364369
// uses the stats from "a"
365-
assertThat(
366-
availableDiskSpaceUpdates.getLast().getBytes(),
367-
// the default 5% (same as flood stage level)
368-
is(Math.max(aFileStore.usableSpace - aFileStore.totalSpace / 20, 0L))
369-
);
370+
assertThat(availableDiskSpaceUpdates.getLast().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-
availableDiskSpaceUpdates.getLast().getBytes(),
401-
// the default 5% (same as flood stage level)
402-
is(Math.max(aFileStore.usableSpace - aFileStore.totalSpace / 20, 0L))
403-
);
401+
assertThat(availableDiskSpaceUpdates.getLast().getBytes(), is(finalAUsableSpace));
404402
} else {
405403
// uses the stats from "b"
406-
assertThat(
407-
availableDiskSpaceUpdates.getLast().getBytes(),
408-
// the default 5% (same as flood stage level)
409-
is(Math.max(bFileStore.usableSpace - bFileStore.totalSpace / 20, 0L))
410-
);
404+
assertThat(availableDiskSpaceUpdates.getLast().getBytes(), is(finalBUsableSpace));
411405
}
412406
}
413407
});

0 commit comments

Comments
 (0)