mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 03:58:21 +00:00
8371559: Intermittent timeouts in test javax/net/ssl/Stapling/HttpsUrlConnClient.java
Reviewed-by: mbaesken, myankelevich
This commit is contained in:
parent
4924b29fa5
commit
af18fbd42d
@ -33,7 +33,11 @@
|
||||
* @run main/othervm HttpsUrlConnClient RSASSA-PSS RSASSA-PSS
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.security.KeyPair;
|
||||
import java.security.KeyPairGenerator;
|
||||
@ -41,7 +45,9 @@ import java.net.Socket;
|
||||
import java.net.URL;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.InetAddress;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
|
||||
import java.security.KeyStore;
|
||||
import java.security.PublicKey;
|
||||
import java.security.Security;
|
||||
@ -55,7 +61,16 @@ import java.security.cert.X509Certificate;
|
||||
import java.security.cert.PKIXRevocationChecker;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import jdk.test.lib.security.SimpleOCSPServer;
|
||||
@ -92,10 +107,6 @@ public class HttpsUrlConnClient {
|
||||
static String INT_ALIAS = "intermediate";
|
||||
static String SSL_ALIAS = "ssl";
|
||||
|
||||
/*
|
||||
* Is the server ready to serve?
|
||||
*/
|
||||
volatile static boolean serverReady = false;
|
||||
volatile int serverPort = 0;
|
||||
|
||||
volatile Exception serverException = null;
|
||||
@ -164,7 +175,7 @@ public class HttpsUrlConnClient {
|
||||
ClientParameters cliParams = new ClientParameters();
|
||||
cliParams.protocols = allowedProts;
|
||||
ServerParameters servParams = new ServerParameters();
|
||||
serverReady = false;
|
||||
CountDownLatch serverReady = new CountDownLatch(1);
|
||||
|
||||
System.out.println("=====================================");
|
||||
System.out.println("Stapling enabled, PKIXParameters with");
|
||||
@ -192,7 +203,7 @@ public class HttpsUrlConnClient {
|
||||
Security.setProperty("ocsp.enable", "false");
|
||||
|
||||
HttpsUrlConnClient sslTest = new HttpsUrlConnClient(cliParams,
|
||||
servParams);
|
||||
servParams, serverReady);
|
||||
TestResult tr = sslTest.getResult();
|
||||
if (!checkClientValidationFailure(tr.clientExc, BasicReason.REVOKED)) {
|
||||
if (tr.clientExc != null) {
|
||||
@ -219,10 +230,11 @@ public class HttpsUrlConnClient {
|
||||
/*
|
||||
* Define the server side of the test.
|
||||
*
|
||||
* If the server prematurely exits, serverReady will be set to true
|
||||
* If the server prematurely exits, serverReady will be counted down
|
||||
* to avoid infinite hangs.
|
||||
*/
|
||||
void doServerSide(ServerParameters servParams) throws Exception {
|
||||
void doServerSide(ServerParameters servParams, CountDownLatch serverReady)
|
||||
throws Exception {
|
||||
|
||||
// Selectively enable or disable the feature
|
||||
System.setProperty("jdk.tls.server.enableStatusRequestExtension",
|
||||
@ -274,7 +286,7 @@ public class HttpsUrlConnClient {
|
||||
/*
|
||||
* Signal Client, we're ready for his connect.
|
||||
*/
|
||||
serverReady = true;
|
||||
serverReady.countDown();
|
||||
|
||||
try (SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
|
||||
BufferedReader in = new BufferedReader(
|
||||
@ -306,18 +318,13 @@ public class HttpsUrlConnClient {
|
||||
/*
|
||||
* Define the client side of the test.
|
||||
*
|
||||
* If the server prematurely exits, serverReady will be set to true
|
||||
* If the server prematurely exits, serverReady will be counted down
|
||||
* to avoid infinite hangs.
|
||||
*/
|
||||
void doClientSide(ClientParameters cliParams) throws Exception {
|
||||
void doClientSide(ClientParameters cliParams, CountDownLatch serverReady)
|
||||
throws Exception {
|
||||
|
||||
// Wait 5 seconds for server ready
|
||||
for (int i = 0; (i < 100 && !serverReady); i++) {
|
||||
Thread.sleep(50);
|
||||
}
|
||||
if (!serverReady) {
|
||||
throw new RuntimeException("Server not ready yet");
|
||||
}
|
||||
serverReady.await();
|
||||
|
||||
// Selectively enable or disable the feature
|
||||
System.setProperty("jdk.tls.client.enableStatusRequestExtension",
|
||||
@ -373,16 +380,16 @@ public class HttpsUrlConnClient {
|
||||
*
|
||||
* Fork off the other side, then do your work.
|
||||
*/
|
||||
HttpsUrlConnClient(ClientParameters cliParams,
|
||||
ServerParameters servParams) throws Exception {
|
||||
HttpsUrlConnClient(ClientParameters cliParams, ServerParameters servParams,
|
||||
CountDownLatch serverReady) throws Exception {
|
||||
Exception startException = null;
|
||||
try {
|
||||
if (separateServerThread) {
|
||||
startServer(servParams, true);
|
||||
startClient(cliParams, false);
|
||||
startServer(servParams, true, serverReady);
|
||||
startClient(cliParams, false, serverReady);
|
||||
} else {
|
||||
startClient(cliParams, true);
|
||||
startServer(servParams, false);
|
||||
startClient(cliParams, true, serverReady);
|
||||
startServer(servParams, false, serverReady);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
startException = e;
|
||||
@ -453,51 +460,53 @@ public class HttpsUrlConnClient {
|
||||
return tr;
|
||||
}
|
||||
|
||||
final void startServer(ServerParameters servParams, boolean newThread)
|
||||
throws Exception {
|
||||
final void startServer(ServerParameters servParams, boolean newThread,
|
||||
CountDownLatch serverReady) throws IOException {
|
||||
if (newThread) {
|
||||
serverThread = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
doServerSide(servParams);
|
||||
doServerSide(servParams, serverReady);
|
||||
} catch (Exception e) {
|
||||
/*
|
||||
* Our server thread just died.
|
||||
*
|
||||
* Release the client, if not active already...
|
||||
*/
|
||||
System.err.println("Server died...");
|
||||
serverReady = true;
|
||||
System.err.println("Server died: " + e);
|
||||
serverException = e;
|
||||
} finally {
|
||||
serverReady.countDown();
|
||||
}
|
||||
}
|
||||
};
|
||||
serverThread.start();
|
||||
} else {
|
||||
try {
|
||||
doServerSide(servParams);
|
||||
doServerSide(servParams, serverReady);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Server died: " + e);
|
||||
serverException = e;
|
||||
} finally {
|
||||
serverReady = true;
|
||||
serverReady.countDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final void startClient(ClientParameters cliParams, boolean newThread)
|
||||
throws Exception {
|
||||
final void startClient(ClientParameters cliParams, boolean newThread,
|
||||
CountDownLatch serverReady) throws Exception {
|
||||
if (newThread) {
|
||||
clientThread = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
doClientSide(cliParams);
|
||||
doClientSide(cliParams, serverReady);
|
||||
} catch (Exception e) {
|
||||
/*
|
||||
* Our client thread just died.
|
||||
*/
|
||||
System.err.println("Client died...");
|
||||
System.err.println("Client died: " + e);
|
||||
clientException = e;
|
||||
}
|
||||
}
|
||||
@ -505,9 +514,10 @@ public class HttpsUrlConnClient {
|
||||
clientThread.start();
|
||||
} else {
|
||||
try {
|
||||
doClientSide(cliParams);
|
||||
doClientSide(cliParams, serverReady);
|
||||
} catch (Exception e) {
|
||||
clientException = e;
|
||||
System.err.println("Client died: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user