Skip to content

Commit 0e86b9c

Browse files
committed
8376610: Test javax/net/ssl/TLS/TestJSSEClientDefaultProtocol.java times out then completed
Reviewed-by: rhalade
1 parent 4507ab8 commit 0e86b9c

2 files changed

Lines changed: 34 additions & 7 deletions

File tree

test/jdk/javax/net/ssl/TLS/CipherTestUtils.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,9 +23,6 @@
2323

2424
import java.io.ByteArrayInputStream;
2525
import java.io.EOFException;
26-
import java.io.File;
27-
import java.io.FileInputStream;
28-
import java.io.FileNotFoundException;
2926
import java.io.IOException;
3027
import java.io.InputStream;
3128
import java.io.OutputStream;
@@ -37,7 +34,6 @@
3734
import java.security.Principal;
3835
import java.security.PrivateKey;
3936
import java.security.SecureRandom;
40-
import java.security.UnrecoverableKeyException;
4137
import java.security.cert.Certificate;
4238
import java.security.cert.CertificateException;
4339
import java.security.cert.CertificateFactory;
@@ -196,6 +192,8 @@ public class CipherTestUtils {
196192
static abstract class Server implements Runnable, AutoCloseable {
197193

198194
final CipherTestUtils cipherTest;
195+
// Thread that uses this server
196+
private volatile Thread serverThread;
199197

200198
Server(CipherTestUtils cipherTest) throws Exception {
201199
this.cipherTest = cipherTest;
@@ -238,6 +236,14 @@ void handleRequest(InputStream in, OutputStream out)
238236
out.write(tp.toString().getBytes());
239237
out.write(" Test PASSED.".getBytes());
240238
}
239+
240+
protected void setServerThread(final Thread serverThread) {
241+
this.serverThread = serverThread;
242+
}
243+
244+
protected final Thread getServerThread() {
245+
return serverThread;
246+
}
241247
}
242248

243249
public static class TestParameters {
@@ -520,6 +526,7 @@ public static Server mainServer(PeerFactory peerFactory,
520526
CipherTestUtils cipherTest = CipherTestUtils.getInstance();
521527
Server srv = peerFactory.newServer(cipherTest, PeerFactory.FREE_PORT);
522528
Thread serverThread = new Thread(srv, "Server");
529+
srv.setServerThread(serverThread);
523530
serverThread.start();
524531

525532
return srv;

test/jdk/javax/net/ssl/TLS/JSSEServer.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,7 @@
2424
import java.io.IOException;
2525
import java.io.InputStream;
2626
import java.io.OutputStream;
27+
import java.net.SocketException;
2728
import javax.net.ssl.KeyManager;
2829
import javax.net.ssl.SSLContext;
2930
import javax.net.ssl.SSLServerSocket;
@@ -44,7 +45,7 @@ public class JSSEServer extends CipherTestUtils.Server {
4445
new TrustManager[]{cipherTest.getServerTrustManager()},
4546
CipherTestUtils.secureRandom);
4647
SSLServerSocketFactory factory =
47-
(SSLServerSocketFactory)serverContext.getServerSocketFactory();
48+
serverContext.getServerSocketFactory();
4849
serverSocket =
4950
(SSLServerSocket) factory.createServerSocket(serverPort);
5051
serverSocket.setEnabledProtocols(protocol.split(","));
@@ -70,6 +71,12 @@ public void run() {
7071
e.printStackTrace(System.out);
7172
}
7273
} catch (Exception e) {
74+
if (e instanceof SocketException && closeServer) {
75+
// letting the server close
76+
System.out.println("SocketException:");
77+
e.printStackTrace(System.out);
78+
break;
79+
}
7380
CipherTestUtils.addFailure(e);
7481
System.out.println("Exception:");
7582
e.printStackTrace(System.out);
@@ -87,5 +94,18 @@ public void close() throws IOException {
8794
if (serverSocket != null && !serverSocket.isClosed()) {
8895
serverSocket.close();
8996
}
97+
98+
final Thread serverThread = getServerThread();
99+
try {
100+
if (serverThread != null &&
101+
serverThread != Thread.currentThread()) {
102+
103+
serverThread.join();
104+
}
105+
} catch (InterruptedException e) {
106+
Thread.currentThread().interrupt();
107+
throw new RuntimeException(
108+
"Interrupted while waiting for server thread", e);
109+
}
90110
}
91111
}

0 commit comments

Comments
 (0)