8039953: [TESTBUG] Timeout java/lang/invoke/MethodHandles/CatchExceptionTest.java
authoriignatyev
Mon, 01 Dec 2014 21:58:46 +0300
changeset 27781 eb64f15b3085
parent 27780 a401c6f316d0
child 27782 5b202512698a
8039953: [TESTBUG] Timeout java/lang/invoke/MethodHandles/CatchExceptionTest.java Reviewed-by: vlivanov, psandoz
jdk/test/java/lang/invoke/MethodHandles/CatchExceptionTest.java
--- a/jdk/test/java/lang/invoke/MethodHandles/CatchExceptionTest.java	Mon Dec 01 21:56:54 2014 +0300
+++ b/jdk/test/java/lang/invoke/MethodHandles/CatchExceptionTest.java	Mon Dec 01 21:58:46 2014 +0300
@@ -24,6 +24,8 @@
 
 import com.oracle.testlibrary.jsr292.Helper;
 import jdk.testlibrary.Asserts;
+import jdk.testlibrary.TimeLimitedRunner;
+import jdk.testlibrary.Utils;
 
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
@@ -33,6 +35,7 @@
 import java.util.function.BiFunction;
 import java.util.function.Function;
 import java.util.function.Supplier;
+import java.util.concurrent.TimeUnit;
 
 /* @test
  * @library /lib/testlibrary/jsr292 /lib/testlibrary/
@@ -93,14 +96,23 @@
     }
 
     public static void main(String[] args) throws Throwable {
+        TestFactory factory = new TestFactory();
+        long timeout = Helper.IS_THOROUGH ? 0L : Utils.adjustTimeout(Utils.DEFAULT_TEST_TIMEOUT);
+        // substract vm init time and reserve time for vm exit
+        timeout *= 0.9;
+        TimeLimitedRunner runner = new TimeLimitedRunner(timeout, 2.0d,
+                () -> {
+                    CatchExceptionTest test = factory.nextTest();
+                    if (test != null) {
+                        test.runTest();
+                        return true;
+                    }
+                    return false;
+                });
         for (CatchExceptionTest test : TestFactory.MANDATORY_TEST_CASES) {
             test.runTest();
         }
-        TestFactory factory = new TestFactory();
-        CatchExceptionTest test;
-        while ((test = factory.nextTest()) != null ) {
-            test.runTest();
-        }
+        runner.call();
     }
 
     private List<Class<?>> getThrowerParams(boolean isVararg, int argsCount) {