Skip to content

Commit

Permalink
Avoid random test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Aug 30, 2024
1 parent fd05885 commit d7905cf
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/test/java/org/apache/commons/io/FileUtilsWaitForTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
public class FileUtilsWaitForTest {

// Assume that this file does not exist
private final File NOSUCHFILE = new File("a.b.c.d."+System.currentTimeMillis());
private final File NOSUCHFILE = new File("a.b.c.d." + System.currentTimeMillis());

@Test
public void testIO_488() throws InterruptedException {
final long start = System.currentTimeMillis();
final AtomicBoolean wasInterrupted = new AtomicBoolean();
final int seconds = 3 ;
final int seconds = 3;
final Thread thread1 = new Thread(() -> {
// This will wait (assuming the file is not found)
assertFalse(FileUtils.waitFor(NOSUCHFILE, seconds), "Should not find file");
Expand All @@ -55,7 +55,7 @@ public void testIO_488() throws InterruptedException {
thread1.join();
assertTrue(wasInterrupted.get(), "Should have been interrupted");
final long elapsed = System.currentTimeMillis() - start;
assertTrue(elapsed >= seconds*1000, "Should wait for n seconds, actual: " + elapsed);
assertTrue(elapsed >= seconds * 1000, "Should wait for n seconds, actual: " + elapsed);
}

@Test
Expand Down Expand Up @@ -92,7 +92,7 @@ public void testWaitFor5Absent() {
}

@Test
@Timeout(value = 30, unit = TimeUnit.MILLISECONDS) // Should complete quickly as the path is present
@Timeout(value = 300, unit = TimeUnit.MILLISECONDS) // Should complete quickly as the path is present
public void testWaitForNegativeDuration() {
assertTrue(FileUtils.waitFor(FileUtils.current(), -1));
}
Expand Down

0 comments on commit d7905cf

Please sign in to comment.