8376610: Test javax/net/ssl/TLS/TestJSSEClientDefaultProtocol.java times out then completed

Reviewed-by: rhalade
This commit is contained in:
Mikhail Yankelevich 2026-05-02 09:22:53 +00:00
parent 4507ab8ae9
commit 0e86b9c94e
2 changed files with 34 additions and 7 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2026, 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
@ -23,9 +23,6 @@
import java.io.ByteArrayInputStream;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@ -37,7 +34,6 @@ import java.security.NoSuchAlgorithmException;
import java.security.Principal;
import java.security.PrivateKey;
import java.security.SecureRandom;
import java.security.UnrecoverableKeyException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
@ -196,6 +192,8 @@ public class CipherTestUtils {
static abstract class Server implements Runnable, AutoCloseable {
final CipherTestUtils cipherTest;
// Thread that uses this server
private volatile Thread serverThread;
Server(CipherTestUtils cipherTest) throws Exception {
this.cipherTest = cipherTest;
@ -238,6 +236,14 @@ public class CipherTestUtils {
out.write(tp.toString().getBytes());
out.write(" Test PASSED.".getBytes());
}
protected void setServerThread(final Thread serverThread) {
this.serverThread = serverThread;
}
protected final Thread getServerThread() {
return serverThread;
}
}
public static class TestParameters {
@ -520,6 +526,7 @@ public class CipherTestUtils {
CipherTestUtils cipherTest = CipherTestUtils.getInstance();
Server srv = peerFactory.newServer(cipherTest, PeerFactory.FREE_PORT);
Thread serverThread = new Thread(srv, "Server");
srv.setServerThread(serverThread);
serverThread.start();
return srv;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2026, 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
@ -24,6 +24,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.SocketException;
import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLServerSocket;
@ -44,7 +45,7 @@ public class JSSEServer extends CipherTestUtils.Server {
new TrustManager[]{cipherTest.getServerTrustManager()},
CipherTestUtils.secureRandom);
SSLServerSocketFactory factory =
(SSLServerSocketFactory)serverContext.getServerSocketFactory();
serverContext.getServerSocketFactory();
serverSocket =
(SSLServerSocket) factory.createServerSocket(serverPort);
serverSocket.setEnabledProtocols(protocol.split(","));
@ -70,6 +71,12 @@ public class JSSEServer extends CipherTestUtils.Server {
e.printStackTrace(System.out);
}
} catch (Exception e) {
if (e instanceof SocketException && closeServer) {
// letting the server close
System.out.println("SocketException:");
e.printStackTrace(System.out);
break;
}
CipherTestUtils.addFailure(e);
System.out.println("Exception:");
e.printStackTrace(System.out);
@ -87,5 +94,18 @@ public class JSSEServer extends CipherTestUtils.Server {
if (serverSocket != null && !serverSocket.isClosed()) {
serverSocket.close();
}
final Thread serverThread = getServerThread();
try {
if (serverThread != null &&
serverThread != Thread.currentThread()) {
serverThread.join();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(
"Interrupted while waiting for server thread", e);
}
}
}