Skip to content

Commit

Permalink
Sort members
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Aug 7, 2024
1 parent cc62ff7 commit fc67901
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/test/java/org/apache/commons/io/FileUtilsWaitForTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@ public class FileUtilsWaitForTest {
// Assume that this file does not exist
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 Thread thread1 = new Thread(() -> {
// This will wait (assuming the file is not found)
assertFalse(FileUtils.waitFor(NOSUCHFILE, seconds), "Should not find file");
wasInterrupted.set(Thread.currentThread().isInterrupted());
});
thread1.start();
Thread.sleep(500); // This should be enough to ensure the waitFor loop has been entered
thread1.interrupt(); // Try to interrupt waitFor
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);
}

@Test
@Timeout(value = 30, unit = TimeUnit.MILLISECONDS) // Should complete quickly as the path is present
public void testWaitFor0() {
Expand All @@ -57,38 +76,19 @@ public void testWaitFor10() {
assertTrue(FileUtils.waitFor(FileUtils.current(), 10));
}

@Test
@Timeout(value = 3, unit = TimeUnit.SECONDS) // Allow for timeout waiting for non-existent file
public void testWaitFor5Absent() {
final long start = System.currentTimeMillis();
assertFalse(FileUtils.waitFor(NOSUCHFILE, 2));
final long elapsed = System.currentTimeMillis() - start;
assertTrue(elapsed >= 2000, "Must reach timeout - expected 2000, actual: " + elapsed);
}

@Test
@Timeout(value = 30, unit = TimeUnit.MILLISECONDS) // Should complete quickly as the path is present
public void testWaitFor100() {
assertTrue(FileUtils.waitFor(FileUtils.current(), 100));
}

@Test
public void testIO_488() throws InterruptedException {
@Timeout(value = 3, unit = TimeUnit.SECONDS) // Allow for timeout waiting for non-existent file
public void testWaitFor5Absent() {
final long start = System.currentTimeMillis();
final AtomicBoolean wasInterrupted = new AtomicBoolean();
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");
wasInterrupted.set(Thread.currentThread().isInterrupted());
});
thread1.start();
Thread.sleep(500); // This should be enough to ensure the waitFor loop has been entered
thread1.interrupt(); // Try to interrupt waitFor
thread1.join();
assertTrue(wasInterrupted.get(), "Should have been interrupted");
assertFalse(FileUtils.waitFor(NOSUCHFILE, 2));
final long elapsed = System.currentTimeMillis() - start;
assertTrue(elapsed >= seconds*1000, "Should wait for n seconds, actual: " + elapsed);
assertTrue(elapsed >= 2000, "Must reach timeout - expected 2000, actual: " + elapsed);
}

@Test
Expand Down

0 comments on commit fc67901

Please sign in to comment.