8129310: java/net/Socket/asyncClose/AsyncClose.java fails intermittently
authorxyin
Tue, 20 Nov 2018 09:59:58 +0800
changeset 52614 2d612914f10b
parent 52613 ed02e6cd595d
child 52615 9a899e2c3e64
8129310: java/net/Socket/asyncClose/AsyncClose.java fails intermittently Reviewed-by: dfuchs
test/jdk/java/net/Socket/asyncClose/AsyncCloseTest.java
test/jdk/java/net/Socket/asyncClose/DatagramSocket_receive.java
test/jdk/java/net/Socket/asyncClose/ServerSocket_accept.java
--- a/test/jdk/java/net/Socket/asyncClose/AsyncCloseTest.java	Mon Nov 19 10:47:38 2018 -0800
+++ b/test/jdk/java/net/Socket/asyncClose/AsyncCloseTest.java	Tue Nov 20 09:59:58 2018 +0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -36,19 +36,20 @@
     }
 
     protected synchronized AsyncCloseTest passed() {
-        if (reason == null)
+        if (failureReason() == null) {
             passed = true;
+        }
         return this;
     }
 
     protected synchronized AsyncCloseTest failed(String r) {
         passed = false;
-        reason = r;
+        reason.append(String.format("%n - %s", r));
         return this;
     }
 
     public synchronized String failureReason() {
-        return reason;
+        return reason.length() > 0 ? reason.toString() : null;
     }
 
     protected synchronized void closed() {
@@ -60,6 +61,6 @@
     }
 
     private boolean passed;
-    private String reason;
+    private final StringBuilder reason = new StringBuilder();
     private boolean closed;
 }
--- a/test/jdk/java/net/Socket/asyncClose/DatagramSocket_receive.java	Mon Nov 19 10:47:38 2018 -0800
+++ b/test/jdk/java/net/Socket/asyncClose/DatagramSocket_receive.java	Tue Nov 20 09:59:58 2018 +0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -40,7 +40,7 @@
     public DatagramSocket_receive(int timeout) throws SocketException {
         this.timeout = timeout;
         latch = new CountDownLatch(1);
-        s = new DatagramSocket();
+        s = new DatagramSocket(0, InetAddress.getLoopbackAddress());
     }
 
     public String description() {
@@ -60,7 +60,7 @@
             }
             latch.countDown();
             s.receive(p);
-            failed("DatagramSocket.receive(DatagramPacket) returned unexpectly!!");
+            failed("DatagramSocket.receive(DatagramPacket) returned unexpectly!!" + " - " + p.getAddress());
         } catch (SocketException se) {
             if (latch.getCount() != 1) {
                 closed();
--- a/test/jdk/java/net/Socket/asyncClose/ServerSocket_accept.java	Mon Nov 19 10:47:38 2018 -0800
+++ b/test/jdk/java/net/Socket/asyncClose/ServerSocket_accept.java	Tue Nov 20 09:59:58 2018 +0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -41,7 +41,7 @@
     public ServerSocket_accept(int timeout) throws IOException {
         this.timeout = timeout;
         latch = new CountDownLatch(1);
-        ss = new ServerSocket(0);
+        ss = new ServerSocket(0, 0, InetAddress.getLoopbackAddress());
     }
 
     public String description() {
@@ -56,7 +56,7 @@
         try {
             latch.countDown();
             Socket s = ss.accept();
-            failed("ServerSocket.accept() returned unexpectly!!");
+            failed("ServerSocket.accept() returned unexpectly!!" + " - " + s);
         } catch (SocketException se) {
             closed();
         } catch (Exception e) {