Repository: commons-io Updated Branches: refs/heads/master a43d2fa2f -> 958657f3c
Avoid fine-sensitivity when testing freeSpace Instead of a fixed delta of 256 kB, assume disk space does not change by more than 1% between calling freeSpacfe and the second call to freeSpaceKb - e.g. 1 GB on a 100 GB drive. 1% is still small enough to detect if the code accidentally changes from kibibytes (1024) to kilobytes (1000) Project: http://git-wip-us.apache.org/repos/asf/commons-io/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-io/commit/e460f4f9 Tree: http://git-wip-us.apache.org/repos/asf/commons-io/tree/e460f4f9 Diff: http://git-wip-us.apache.org/repos/asf/commons-io/diff/e460f4f9 Branch: refs/heads/master Commit: e460f4f93817bea10b2fba8aaddeb892421d2668 Parents: 14b52eb Author: Stian Soiland-Reyes <[email protected]> Authored: Wed Sep 27 22:22:52 2017 +0100 Committer: Stian Soiland-Reyes <[email protected]> Committed: Wed Sep 27 22:48:15 2017 +0100 ---------------------------------------------------------------------- .../org/apache/commons/io/FileSystemUtilsTestCase.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-io/blob/e460f4f9/src/test/java/org/apache/commons/io/FileSystemUtilsTestCase.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/io/FileSystemUtilsTestCase.java b/src/test/java/org/apache/commons/io/FileSystemUtilsTestCase.java index 96f0013..399c4ce 100644 --- a/src/test/java/org/apache/commons/io/FileSystemUtilsTestCase.java +++ b/src/test/java/org/apache/commons/io/FileSystemUtilsTestCase.java @@ -78,15 +78,22 @@ public class FileSystemUtilsTestCase { // now perform the test final long free = FileSystemUtils.freeSpace("/"); final long kb = FileSystemUtils.freeSpaceKb("/"); + // Assume disk space does not fluctuate + // more than 1% between the above two calls; + // this also also small enough to verifiy freeSpaceKb uses + // kibibytes (1024) instead of SI kilobytes (1000) + double acceptableDelta = kb * 0.01d; if (kilobyteBlock) { - assertEquals(free, kb, 256d); + assertEquals(free, kb, acceptableDelta); } else { - assertEquals(free / 2d, kb, 256d); + assertEquals(free / 2d, kb, acceptableDelta); } } else { final long bytes = FileSystemUtils.freeSpace(""); final long kb = FileSystemUtils.freeSpaceKb(""); - assertEquals((double) bytes / 1024, kb, 256d); + // Assume disk space does not fluctuate more than 1% + double acceptableDelta = kb * 0.01d; + assertEquals((double) bytes / 1024, kb, acceptableDelta); } }
