Skip to content

Commit aa47dc7

Browse files
author
Amos Shi
committedJun 23, 2024
8310070: Test: javax/net/ssl/DTLS/DTLSWontNegotiateV10.java timed out
Backport-of: af7f95e24ad5981c5de4b5dbf37da6f4f5e42129
1 parent 9a45e2d commit aa47dc7

File tree

1 file changed

+44
-14
lines changed

1 file changed

+44
-14
lines changed
 

‎test/jdk/javax/net/ssl/DTLS/DTLSWontNegotiateV10.java

+44-14
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public class DTLSWontNegotiateV10 {
4848
private static final String DTLS = "DTLS";
4949
private static final String DTLSV_1_2 = "DTLSv1.2";
5050

51+
private static final int READ_TIMEOUT_SECS = Integer.getInteger("readtimeout", 30);
52+
5153
public static void main(String[] args) throws Exception {
5254
if (args[0].equals(DTLSV_1_0)) {
5355
SecurityUtils.removeFromDisabledTlsAlgs(DTLSV_1_0);
@@ -63,20 +65,43 @@ public static void main(String[] args) throws Exception {
6365
} else {
6466
// server process
6567
// args: protocol
66-
try (DTLSServer server = new DTLSServer(args[0])) {
67-
List<String> command = List.of(
68-
Path.of(System.getProperty("java.home"), "bin", "java").toString(),
69-
"DTLSWontNegotiateV10",
70-
// if server is "DTLS" then the client should be v1.0 and vice versa
71-
args[0].equals(DTLS) ? DTLSV_1_0 : DTLS,
72-
Integer.toString(server.getListeningPortNumber())
73-
);
74-
75-
ProcessBuilder builder = new ProcessBuilder(command);
76-
Process p = builder.inheritIO().start();
77-
server.run();
78-
p.destroy();
79-
System.out.println("Success: DTLSv1.0 connection was not established.");
68+
final int totalAttempts = 5;
69+
int tries;
70+
for (tries = 0 ; tries < totalAttempts ; ++tries) {
71+
try {
72+
System.out.printf("Starting server %d/%d attempts%n", tries+1, totalAttempts);
73+
runServer(args[0]);
74+
break;
75+
} catch (SocketTimeoutException exc) {
76+
System.out.println("The server timed-out waiting for packets from the client.");
77+
}
78+
}
79+
if (tries == totalAttempts) {
80+
throw new RuntimeException("The server/client communications timed-out after " + totalAttempts + " tries.");
81+
}
82+
}
83+
}
84+
85+
private static void runServer(String protocol) throws Exception {
86+
// args: protocol
87+
Process clientProcess = null;
88+
try (DTLSServer server = new DTLSServer(protocol)) {
89+
List<String> command = List.of(
90+
Path.of(System.getProperty("java.home"), "bin", "java").toString(),
91+
"DTLSWontNegotiateV10",
92+
// if server is "DTLS" then the client should be v1.0 and vice versa
93+
protocol.equals(DTLS) ? DTLSV_1_0 : DTLS,
94+
Integer.toString(server.getListeningPortNumber())
95+
);
96+
97+
ProcessBuilder builder = new ProcessBuilder(command);
98+
clientProcess = builder.inheritIO().start();
99+
server.run();
100+
System.out.println("Success: DTLSv1.0 connection was not established.");
101+
102+
} finally {
103+
if (clientProcess != null) {
104+
clientProcess.destroy();
80105
}
81106
}
82107
}
@@ -89,6 +114,9 @@ private static class DTLSClient extends DTLSEndpoint {
89114
public DTLSClient(String protocol, int portNumber) throws Exception {
90115
super(true, protocol);
91116
remotePort = portNumber;
117+
socket.setSoTimeout(READ_TIMEOUT_SECS * 1000);
118+
log("Client listening on port " + socket.getLocalPort()
119+
+ ". Sending data to server port " + remotePort);
92120
log("Enabled protocols: " + String.join(" ", engine.getEnabledProtocols()));
93121
}
94122

@@ -287,6 +315,8 @@ private static class DTLSServer extends DTLSEndpoint implements AutoCloseable {
287315

288316
public DTLSServer(String protocol) throws Exception {
289317
super(false, protocol);
318+
socket.setSoTimeout(READ_TIMEOUT_SECS * 1000);
319+
log("Server listening on port: " + socket.getLocalPort());
290320
log("Enabled protocols: " + String.join(" ", engine.getEnabledProtocols()));
291321
}
292322

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Jun 23, 2024

@openjdk-notifier[bot]
Please sign in to comment.