changeset 11603:dde6e2f32ad2

8139373: [TEST_BUG] java/net/MulticastSocket/MultiDead.java failed with timeout Reviewed-by: chegar
author igerasim
date Thu, 29 Oct 2015 22:41:34 +0300
parents 5bab7361c6a3
children 017db73c712c
files test/java/net/MulticastSocket/MultiDead.java test/lib/testlibrary/jdk/testlibrary/Utils.java
diffstat 2 files changed, 16 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/net/MulticastSocket/MultiDead.java	Wed Oct 28 15:43:06 2015 -0700
+++ b/test/java/net/MulticastSocket/MultiDead.java	Thu Oct 29 22:41:34 2015 +0300
@@ -35,11 +35,17 @@
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.concurrent.CountDownLatch;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import jdk.testlibrary.JDKToolLauncher;
+import jdk.testlibrary.Utils;
 
 public class MultiDead {
     private static final int THREAD_PAIR_COUNT = 4;
     private static final int CHILDREN_COUNT = 20;
+    // at least 2.5 seconds for a child to complete
+    private static final long CHILD_TIMEOUT = 2500;
+    private static final long TIMEOUT =
+        Utils.adjustTimeout(CHILDREN_COUNT * CHILD_TIMEOUT * 2);
 
     public static void main(String[] args) throws Throwable {
         if (args.length == 0 || args[0].equals("parent")) {
@@ -65,6 +71,7 @@
             for (int i = 0; i < CHILDREN_COUNT; ++i) {
                 System.out.println("child #" + (i + 1) + " of " +
                         CHILDREN_COUNT);
+                long start = System.nanoTime();
                 try {
                     child.set(pb.start());
                     child.get().waitFor();
@@ -74,11 +81,18 @@
                 } catch (Exception e) {
                     throw new RuntimeException(e);
                 }
+                if (System.nanoTime() - start >
+                        MILLISECONDS.toNanos(CHILD_TIMEOUT)) {
+                    System.err.println("Machine is too slow, " +
+                            "skipping the test...");
+                    break;
+                }
             }
         });
 
         th.start();
-        th.join(CHILDREN_COUNT * 1000); // 1 sec for a child to complete
+        th.join(TIMEOUT);
+
         stopFlag.set(true);
         if (th.isAlive()) {
             if (child.get() != null) {
--- a/test/lib/testlibrary/jdk/testlibrary/Utils.java	Wed Oct 28 15:43:06 2015 -0700
+++ b/test/lib/testlibrary/jdk/testlibrary/Utils.java	Thu Oct 29 22:41:34 2015 +0300
@@ -66,7 +66,7 @@
     public static final double TIMEOUT_FACTOR;
     static {
         String toFactor = System.getProperty("test.timeout.factor", "1.0");
-       TIMEOUT_FACTOR = Double.parseDouble(toFactor);
+        TIMEOUT_FACTOR = Double.parseDouble(toFactor);
     }
 
     /**