changeset 11042:fc2baad47405

8137230: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out Reviewed-by: rriggs
author igerasim
date Fri, 09 Oct 2015 20:12:07 +0300
parents 202de41724fa
children 5590c514b20b
files test/java/nio/channels/FileChannel/LoopingTruncate.java
diffstat 1 files changed, 20 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/nio/channels/FileChannel/LoopingTruncate.java	Fri Oct 09 20:11:18 2015 +0300
+++ b/test/java/nio/channels/FileChannel/LoopingTruncate.java	Fri Oct 09 20:12:07 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 {