8134599: TEST_BUG: java/rmi/transport/closeServerSocket/CloseServerSocket.java fails intermittently with Address already in use
authormli
Thu, 17 Oct 2019 13:34:06 +0800
changeset 58661 d2108d9fc4f5
parent 58660 7a81cc7ca25c
child 58662 5b7a967da646
8134599: TEST_BUG: java/rmi/transport/closeServerSocket/CloseServerSocket.java fails intermittently with Address already in use Reviewed-by: weijun, darcy, rriggs, coffeys
test/jdk/java/rmi/transport/closeServerSocket/CloseServerSocket.java
--- a/test/jdk/java/rmi/transport/closeServerSocket/CloseServerSocket.java	Thu Oct 17 13:18:01 2019 +0800
+++ b/test/jdk/java/rmi/transport/closeServerSocket/CloseServerSocket.java	Thu Oct 17 13:34:06 2019 +0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -63,8 +63,19 @@
         verifyPortInUse(PORT);
         UnicastRemoteObject.unexportObject(registry, true);
         System.err.println("- unexported registry");
-        Thread.sleep(1000);        // work around BindException (bug?)
-        verifyPortFree(PORT);
+        int tries = (int)TestLibrary.getTimeoutFactor();
+        tries = Math.max(tries, 1);
+        while (tries-- > 0) {
+            Thread.sleep(1000);
+            try {
+                verifyPortFree(PORT);
+                break;
+            } catch (IOException ignore) { }
+        }
+        if (tries < 0) {
+            throw new RuntimeException("time out after tries: " + tries);
+        }
+
 
         /*
          * The follow portion of this test is disabled temporarily
@@ -101,6 +112,7 @@
     private static void verifyPortInUse(int port) throws IOException {
         try {
             verifyPortFree(port);
+            throw new RuntimeException("port is not in use: " + port);
         } catch (BindException e) {
             System.err.println("- port " + port + " is in use");
             return;