Mercurial > hg > release > icedtea7-forest-2.6 > jdk
changeset 8963:04922015b635
8139373, PR3162: [TEST_BUG] java/net/MulticastSocket/MultiDead.java failed with timeout
Reviewed-by: chegar
author | igerasim |
---|---|
date | Thu, 27 Oct 2016 02:44:35 +0100 |
parents | bc86cb0b4331 |
children | b03ecf9d57c9 |
files | test/java/net/MulticastSocket/MultiDead.java test/lib/testlibrary/jdk/testlibrary/Utils.java |
diffstat | 2 files changed, 49 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/test/java/net/MulticastSocket/MultiDead.java Thu Oct 15 14:41:37 2015 +0100 +++ b/test/java/net/MulticastSocket/MultiDead.java Thu Oct 27 02:44:35 2016 +0100 @@ -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")) { @@ -62,25 +68,33 @@ final AtomicBoolean stopFlag = new AtomicBoolean(false); Thread th = new Thread(new Runnable() { - @Override - public void run() { - for (int i = 0; i < CHILDREN_COUNT; ++i) { - System.out.println("child #" + (i + 1) + " of " + - CHILDREN_COUNT); - try { - child.set(pb.start()); - child.get().waitFor(); - if (stopFlag.get()) { - break; - } - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } - }); + @Override + public void run() { + 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(); + if (stopFlag.get()) { + break; + } + } 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) { @@ -94,26 +108,26 @@ final CountDownLatch latch = new CountDownLatch(1); for (int i = 0; i < THREAD_PAIR_COUNT; ++i) { new Thread(new Runnable() { - @Override - public void run() { + @Override + public void run() { try { - latch.await(); - try (MulticastSocket a = new MulticastSocket(6000)) { - } - } catch (Exception ignore) {} - } + latch.await(); + try (MulticastSocket a = new MulticastSocket(6000)) { + } + } catch (Exception ignore) {} + } }).start(); new Thread(new Runnable() { - @Override - public void run() { - try { - latch.await(); - try (DatagramSocket b = new DatagramSocket(6000)) { - } - } catch (Exception ignore) {} - } - }).start(); + @Override + public void run() { + try { + latch.await(); + try (DatagramSocket b = new DatagramSocket(6000)) { + } + } catch (Exception ignore) {} + } + }).start(); } latch.countDown(); }
--- a/test/lib/testlibrary/jdk/testlibrary/Utils.java Thu Oct 15 14:41:37 2015 +0100 +++ b/test/lib/testlibrary/jdk/testlibrary/Utils.java Thu Oct 27 02:44:35 2016 +0100 @@ -65,7 +65,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); } /**