7170308: timing error in the krb5 test SSL.java
authorweijun
Mon, 21 May 2012 15:40:30 +0800
changeset 12701 c624acdf1852
parent 12700 9c9ad46c7c40
child 12702 fb8b5f2a4389
7170308: timing error in the krb5 test SSL.java Reviewed-by: xuelei
jdk/test/sun/security/krb5/auto/SSL.java
--- a/jdk/test/sun/security/krb5/auto/SSL.java	Fri May 18 12:29:33 2012 -0700
+++ b/jdk/test/sun/security/krb5/auto/SSL.java	Mon May 21 15:40:30 2012 +0800
@@ -53,6 +53,9 @@
     private static volatile String server;
     private static volatile int port;
 
+    // 0-Not started, 1-Start OK, 2-Failure
+    private static volatile int serverState = 0;
+
     public static void main(String[] args) throws Exception {
 
         krb5Cipher = args[0];
@@ -109,14 +112,20 @@
                     s.doAs(new JsseServerAction(), null);
                 } catch (Exception e) {
                     e.printStackTrace();
+                    serverState = 2;
                 }
             }
         });
         server.setDaemon(true);
         server.start();
 
-        // Warm the server
-        Thread.sleep(2000);
+        while (serverState == 0) {
+            Thread.sleep(50);
+        }
+
+        if (serverState == 2) {
+            throw new Exception("Server already failed");
+        }
 
         // Now create the keytab
 
@@ -214,6 +223,7 @@
                 (SSLServerSocket) sslssf.createServerSocket(0); // any port
             port = sslServerSocket.getLocalPort();
             System.out.println("Listening on " + port);
+            serverState = 1;
 
             // Enable only a KRB5 cipher suite.
             String enabledSuites[] = {krb5Cipher};