8137230: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out
authorigerasim
Tue, 29 Sep 2015 17:26:14 +0300
changeset 32836 68073065a22f
parent 32835 8bfe2ea5617d
child 32837 e331a1a5a621
8137230: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out Reviewed-by: rriggs
jdk/test/java/nio/channels/FileChannel/LoopingTruncate.java
--- a/jdk/test/java/nio/channels/FileChannel/LoopingTruncate.java	Mon Sep 28 16:39:12 2015 +0300
+++ b/jdk/test/java/nio/channels/FileChannel/LoopingTruncate.java	Tue Sep 29 17:26:14 2015 +0300
@@ -23,32 +23,39 @@
 
 /**
  * @test
- * @bug 8137121
+ * @bug 8137121 8137230
  * @summary (fc) Infinite loop FileChannel.truncate
+ * @library /lib/testlibrary
+ * @build jdk.testlibrary.Utils
  * @run main/othervm LoopingTruncate
  */
 
 import java.nio.ByteBuffer;
 import java.nio.channels.FileChannel;
+import java.nio.channels.ClosedByInterruptException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import static java.nio.file.StandardOpenOption.*;
+import static jdk.testlibrary.Utils.adjustTimeout;
 
 public class LoopingTruncate {
 
     // (int)FATEFUL_SIZE == -3 == IOStatus.INTERRUPTED
     static long FATEFUL_SIZE = 0x1FFFFFFFDL;
 
-    static long TIMEOUT = 10_000; // 10 seconds
+    // At least 20 seconds
+    static long TIMEOUT = adjustTimeout(20_000);
 
     public static void main(String[] args) throws Throwable {
         Path path = Files.createTempFile("LoopingTruncate.tmp", null);
-        try {
+        try (FileChannel fc = FileChannel.open(path, CREATE, WRITE)) {
+            fc.position(FATEFUL_SIZE + 1L);
+            fc.write(ByteBuffer.wrap(new byte[] {0}));
+
             Thread th = new Thread(() -> {
-                try (FileChannel fc = FileChannel.open(path, CREATE, WRITE)) {
-                    fc.position(FATEFUL_SIZE + 1L);
-                    fc.write(ByteBuffer.wrap(new byte[] {0}));
+                try {
                     fc.truncate(FATEFUL_SIZE);
+                } catch (ClosedByInterruptException ignore) {
                 } catch (Exception e) {
                     throw new RuntimeException(e);
                 }});
@@ -56,7 +63,14 @@
             th.join(TIMEOUT);
 
             if (th.isAlive()) {
+                System.err.println("=== Stack trace of the guilty thread:");
+                for (StackTraceElement el : th.getStackTrace()) {
+                    System.err.println("\t" + el);
+                }
+                System.err.println("===");
+
                 th.interrupt();
+                th.join();
                 throw new RuntimeException("Failed to complete on time");
             }
         } finally {