Skip to content

Commit

Permalink
8310070: Test: javax/net/ssl/DTLS/DTLSWontNegotiateV10.java timed out
Browse files Browse the repository at this point in the history
Backport-of: af7f95e24ad5981c5de4b5dbf37da6f4f5e42129
  • Loading branch information
GoeLin committed Mar 7, 2024
1 parent 47c67bd commit 2267292
Showing 1 changed file with 44 additions and 14 deletions.
58 changes: 44 additions & 14 deletions test/jdk/javax/net/ssl/DTLS/DTLSWontNegotiateV10.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class DTLSWontNegotiateV10 {
private static final String DTLS = "DTLS";
private static final String DTLSV_1_2 = "DTLSv1.2";

private static final int READ_TIMEOUT_SECS = Integer.getInteger("readtimeout", 30);

public static void main(String[] args) throws Exception {
if (args[0].equals(DTLSV_1_0)) {
SecurityUtils.removeFromDisabledTlsAlgs(DTLSV_1_0);
Expand All @@ -63,20 +65,43 @@ public static void main(String[] args) throws Exception {
} else {
// server process
// args: protocol
try (DTLSServer server = new DTLSServer(args[0])) {
List<String> command = List.of(
Path.of(System.getProperty("java.home"), "bin", "java").toString(),
"DTLSWontNegotiateV10",
// if server is "DTLS" then the client should be v1.0 and vice versa
args[0].equals(DTLS) ? DTLSV_1_0 : DTLS,
Integer.toString(server.getListeningPortNumber())
);

ProcessBuilder builder = new ProcessBuilder(command);
Process p = builder.inheritIO().start();
server.run();
p.destroy();
System.out.println("Success: DTLSv1.0 connection was not established.");
final int totalAttempts = 5;
int tries;
for (tries = 0 ; tries < totalAttempts ; ++tries) {
try {
System.out.printf("Starting server %d/%d attempts%n", tries+1, totalAttempts);
runServer(args[0]);
break;
} catch (SocketTimeoutException exc) {
System.out.println("The server timed-out waiting for packets from the client.");
}
}
if (tries == totalAttempts) {
throw new RuntimeException("The server/client communications timed-out after " + totalAttempts + " tries.");
}
}
}

private static void runServer(String protocol) throws Exception {
// args: protocol
Process clientProcess = null;
try (DTLSServer server = new DTLSServer(protocol)) {
List<String> command = List.of(
Path.of(System.getProperty("java.home"), "bin", "java").toString(),
"DTLSWontNegotiateV10",
// if server is "DTLS" then the client should be v1.0 and vice versa
protocol.equals(DTLS) ? DTLSV_1_0 : DTLS,
Integer.toString(server.getListeningPortNumber())
);

ProcessBuilder builder = new ProcessBuilder(command);
clientProcess = builder.inheritIO().start();
server.run();
System.out.println("Success: DTLSv1.0 connection was not established.");

} finally {
if (clientProcess != null) {
clientProcess.destroy();
}
}
}
Expand All @@ -89,6 +114,9 @@ private static class DTLSClient extends DTLSEndpoint {
public DTLSClient(String protocol, int portNumber) throws Exception {
super(true, protocol);
remotePort = portNumber;
socket.setSoTimeout(READ_TIMEOUT_SECS * 1000);
log("Client listening on port " + socket.getLocalPort()
+ ". Sending data to server port " + remotePort);
log("Enabled protocols: " + String.join(" ", engine.getEnabledProtocols()));
}

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

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

Expand Down

1 comment on commit 2267292

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.