Skip to content

Commit

Permalink
[hotfix][filesystems][test] Fix improper usage of System.nanoTime().
Browse files Browse the repository at this point in the history
Per the JavaDoc of System.nanoTime(), we should use `t1 - t0 < 0` rather than `t1 < t0` because of the possibility of numerical overflow.
  • Loading branch information
xintongsong authored and aljoscha committed May 25, 2020
1 parent d88c195 commit 656e8dc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static void checkPathEventualExistence(
long deadline) throws IOException, InterruptedException {
boolean dirExists;
while ((dirExists = fs.exists(path)) != expectedExists &&
System.nanoTime() < deadline) {
System.nanoTime() - deadline < 0) {
Thread.sleep(10);
}
assertEquals(expectedExists, dirExists);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static void teardown() throws IOException, InterruptedException {
}

public static void cleanupDirectoryWithRetry(FileSystem fs, Path path, long deadline) throws IOException, InterruptedException {
while (fs.exists(path) && System.nanoTime() < deadline) {
while (fs.exists(path) && System.nanoTime() - deadline < 0) {
fs.delete(path, true);
Thread.sleep(50L);
}
Expand Down

0 comments on commit 656e8dc

Please sign in to comment.