test/jdk/java/net/Socket/asyncClose/Race.java
changeset 55045 3a8433d967ea
parent 49573 6b46983d6fbe
--- a/test/jdk/java/net/Socket/asyncClose/Race.java	Thu May 23 15:15:01 2019 +0200
+++ b/test/jdk/java/net/Socket/asyncClose/Race.java	Mon May 27 13:29:11 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2019, 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
@@ -28,6 +28,8 @@
  */
 
 import java.io.InputStream;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.net.ConnectException;
@@ -40,12 +42,14 @@
     final static int THREADS = 100;
 
     public static void main(String[] args) throws Exception {
-        try (ServerSocket ss = new ServerSocket(0)) {
+        try (ServerSocket ss = new ServerSocket()) {
+            InetAddress loopback = InetAddress.getLoopbackAddress();
+            ss.bind(new InetSocketAddress(loopback, 0));
             final int port = ss.getLocalPort();
             final Phaser phaser = new Phaser(THREADS + 1);
             for (int i=0; i<100; i++) {
                 try {
-                    final Socket s = new Socket("localhost", port);
+                    final Socket s = new Socket(loopback, port);
                     s.setSoLinger(false, 0);
                     try (Socket sa = ss.accept()) {
                         sa.setSoLinger(false, 0);