@@ -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