Mercurial > hg > release > icedtea7-forest-2.6 > jdk
changeset 8961:2751730ffae1
8137230, PR3162: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out
Summary: Includes changes to Utils from 8022221 (TIMEOUT_FACTOR) & 8059070 (adjustTimeout)
Reviewed-by: rriggs
author | igerasim |
---|---|
date | Thu, 27 Oct 2016 02:27:38 +0100 |
parents | 8aaee9c91c63 |
children | bc86cb0b4331 |
files | test/java/nio/channels/FileChannel/LoopingTruncate.java test/lib/testlibrary/jdk/testlibrary/Utils.java |
diffstat | 2 files changed, 47 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 Thu Oct 27 02:27:38 2016 +0100 @@ -23,34 +23,41 @@ /** * @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 { final 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(new Runnable() { @Override public void run() { - 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); } @@ -60,7 +67,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 {
--- a/test/lib/testlibrary/jdk/testlibrary/Utils.java Fri Oct 09 20:11:18 2015 +0300 +++ b/test/lib/testlibrary/jdk/testlibrary/Utils.java Thu Oct 27 02:27:38 2016 +0100 @@ -35,6 +35,7 @@ import java.util.Collections; import java.util.regex.Pattern; import java.util.regex.Matcher; +import java.util.concurrent.TimeUnit; /** * Common library for various test helper functions. @@ -57,6 +58,22 @@ public static final String JAVA_OPTIONS = System.getProperty("test.java.opts", "").trim(); + /** + * Returns the value of 'test.timeout.factor' system property + * converted to {@code double}. + */ + public static final double TIMEOUT_FACTOR; + static { + String toFactor = System.getProperty("test.timeout.factor", "1.0"); + TIMEOUT_FACTOR = Double.parseDouble(toFactor); + } + + /** + * Returns the value of JTREG default test timeout in milliseconds + * converted to {@code long}. + */ + public static final long DEFAULT_TEST_TIMEOUT = TimeUnit.SECONDS.toMillis(120); + private Utils() { // Private constructor to prevent class instantiation } @@ -229,4 +246,14 @@ throw t; } } + + /** + * Adjusts the provided timeout value for the TIMEOUT_FACTOR + * @param tOut the timeout value to be adjusted + * @return The timeout value adjusted for the value of "test.timeout.factor" + * system property + */ + public static long adjustTimeout(long tOut) { + return Math.round(tOut * Utils.TIMEOUT_FACTOR); + } }