8027612: java/io/File/MaxPathLength.java fails intermittently in the clean-up stage
authordxu
Mon, 04 Nov 2013 15:48:08 -0800
changeset 21611 34085733bead
parent 21610 7347576ad354
child 21612 1f01e1f74f96
8027612: java/io/File/MaxPathLength.java fails intermittently in the clean-up stage Reviewed-by: chegar
jdk/test/java/io/File/MaxPathLength.java
--- a/jdk/test/java/io/File/MaxPathLength.java	Mon Nov 04 15:21:47 2013 +0100
+++ b/jdk/test/java/io/File/MaxPathLength.java	Mon Nov 04 15:48:08 2013 -0800
@@ -28,6 +28,8 @@
 
 import java.io.*;
 import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.DirectoryNotEmptyException;
 
 public class MaxPathLength {
     private static String sep = File.separator;
@@ -182,7 +184,18 @@
         } finally {
             // Clean up
             for (int i = 0; i < max; i++) {
-                Files.deleteIfExists((new File(created[i])).toPath());
+                Path p = (new File(created[i])).toPath();
+                try {
+                    Files.deleteIfExists(p);
+                    // Test if the file is really deleted and wait for 1 second at most
+                    for (int j = 0; j < 10 && Files.exists(p); j++) {
+                        Thread.sleep(100);
+                    }
+                } catch (DirectoryNotEmptyException ex) {
+                    // Give up the clean-up, let jtreg handle it.
+                    System.err.println("Dir, " + p + ", is not empty");
+                    break;
+                }
             }
         }
     }