@@ -39,6 +39,25 @@ public class FileUtilsWaitForTest {
3939 // Assume that this file does not exist
4040 private final File NOSUCHFILE = new File ("a.b.c.d." +System .currentTimeMillis ());
4141
42+ @ Test
43+ public void testIO_488 () throws InterruptedException {
44+ final long start = System .currentTimeMillis ();
45+ final AtomicBoolean wasInterrupted = new AtomicBoolean ();
46+ final int seconds = 3 ;
47+ final Thread thread1 = new Thread (() -> {
48+ // This will wait (assuming the file is not found)
49+ assertFalse (FileUtils .waitFor (NOSUCHFILE , seconds ), "Should not find file" );
50+ wasInterrupted .set (Thread .currentThread ().isInterrupted ());
51+ });
52+ thread1 .start ();
53+ Thread .sleep (500 ); // This should be enough to ensure the waitFor loop has been entered
54+ thread1 .interrupt (); // Try to interrupt waitFor
55+ thread1 .join ();
56+ assertTrue (wasInterrupted .get (), "Should have been interrupted" );
57+ final long elapsed = System .currentTimeMillis () - start ;
58+ assertTrue (elapsed >= seconds *1000 , "Should wait for n seconds, actual: " + elapsed );
59+ }
60+
4261 @ Test
4362 @ Timeout (value = 30 , unit = TimeUnit .MILLISECONDS ) // Should complete quickly as the path is present
4463 public void testWaitFor0 () {
@@ -57,38 +76,19 @@ public void testWaitFor10() {
5776 assertTrue (FileUtils .waitFor (FileUtils .current (), 10 ));
5877 }
5978
60- @ Test
61- @ Timeout (value = 3 , unit = TimeUnit .SECONDS ) // Allow for timeout waiting for non-existent file
62- public void testWaitFor5Absent () {
63- final long start = System .currentTimeMillis ();
64- assertFalse (FileUtils .waitFor (NOSUCHFILE , 2 ));
65- final long elapsed = System .currentTimeMillis () - start ;
66- assertTrue (elapsed >= 2000 , "Must reach timeout - expected 2000, actual: " + elapsed );
67- }
68-
6979 @ Test
7080 @ Timeout (value = 30 , unit = TimeUnit .MILLISECONDS ) // Should complete quickly as the path is present
7181 public void testWaitFor100 () {
7282 assertTrue (FileUtils .waitFor (FileUtils .current (), 100 ));
7383 }
7484
7585 @ Test
76- public void testIO_488 () throws InterruptedException {
86+ @ Timeout (value = 3 , unit = TimeUnit .SECONDS ) // Allow for timeout waiting for non-existent file
87+ public void testWaitFor5Absent () {
7788 final long start = System .currentTimeMillis ();
78- final AtomicBoolean wasInterrupted = new AtomicBoolean ();
79- final int seconds = 3 ;
80- final Thread thread1 = new Thread (() -> {
81- // This will wait (assuming the file is not found)
82- assertFalse (FileUtils .waitFor (NOSUCHFILE , seconds ), "Should not find file" );
83- wasInterrupted .set (Thread .currentThread ().isInterrupted ());
84- });
85- thread1 .start ();
86- Thread .sleep (500 ); // This should be enough to ensure the waitFor loop has been entered
87- thread1 .interrupt (); // Try to interrupt waitFor
88- thread1 .join ();
89- assertTrue (wasInterrupted .get (), "Should have been interrupted" );
89+ assertFalse (FileUtils .waitFor (NOSUCHFILE , 2 ));
9090 final long elapsed = System .currentTimeMillis () - start ;
91- assertTrue (elapsed >= seconds * 1000 , "Should wait for n seconds , actual: " + elapsed );
91+ assertTrue (elapsed >= 2000 , "Must reach timeout - expected 2000 , actual: " + elapsed );
9292 }
9393
9494 @ Test
0 commit comments