diff --git a/lib3270j/src/test/java/haus/nightmare/lib3270j/telnet/ProxyConnectionTest.java b/lib3270j/src/test/java/haus/nightmare/lib3270j/telnet/ProxyConnectionTest.java index b3e7240..e02118b 100644 --- a/lib3270j/src/test/java/haus/nightmare/lib3270j/telnet/ProxyConnectionTest.java +++ b/lib3270j/src/test/java/haus/nightmare/lib3270j/telnet/ProxyConnectionTest.java @@ -1,6 +1,9 @@ package haus.nightmare.lib3270j.telnet; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.ResourceAccessMode; +import org.junit.jupiter.api.parallel.ResourceLock; +import org.junit.jupiter.api.parallel.Resources; import haus.nightmare.lib3270j.ConnectionConfig; import haus.nightmare.lib3270j.TerminalModel; @@ -102,7 +105,7 @@ public class ProxyConnectionTest { connection.connect(); assertTrue(connection.isConnected()); - String req = receivedRequest.get(3, TimeUnit.SECONDS); + String req = receivedRequest.get(5, TimeUnit.SECONDS); assertTrue(req.startsWith("CONNECT target.mainframe.org:23 HTTP/1.1"), "Expected CONNECT request"); assertTrue(req.contains("Proxy-Authorization: Basic "), "Expected Basic auth in proxy request"); @@ -156,7 +159,7 @@ public class ProxyConnectionTest { connection.connect(); assertTrue(connection.isConnected()); - assertTrue(handshakeDone.await(3, TimeUnit.SECONDS)); + assertTrue(handshakeDone.await(5, TimeUnit.SECONDS)); connection.disconnect(); } @@ -236,13 +239,14 @@ public class ProxyConnectionTest { connection.connect(); assertTrue(connection.isConnected()); - assertTrue(handshakeDone.await(3, TimeUnit.SECONDS)); + assertTrue(handshakeDone.await(5, TimeUnit.SECONDS)); connection.disconnect(); } } @Test + @ResourceLock(value = Resources.SYSTEM_PROPERTIES, mode = ResourceAccessMode.READ_WRITE) public void testSystemPropertiesProxyFallback() throws Exception { try (ServerSocket proxyServer = new ServerSocket(0)) { int proxyPort = proxyServer.getLocalPort(); @@ -259,6 +263,9 @@ public class ProxyConnectionTest { out.write("HTTP/1.1 200 OK\r\n\r\n".getBytes(StandardCharsets.US_ASCII)); out.flush(); serverHandshakeDone.countDown(); + + // Keep socket open and drain data until client disconnects + while (clientSock.getInputStream().read() != -1) {} } catch (Exception ignored) {} }); serverThread.setDaemon(true); @@ -266,7 +273,11 @@ public class ProxyConnectionTest { String origHost = System.getProperty("http.proxyHost"); String origPort = System.getProperty("http.proxyPort"); + String origSocksHost = System.getProperty("socksProxyHost"); + String origSocksPort = System.getProperty("socksProxyPort"); try { + System.clearProperty("socksProxyHost"); + System.clearProperty("socksProxyPort"); System.setProperty("http.proxyHost", "127.0.0.1"); System.setProperty("http.proxyPort", String.valueOf(proxyPort)); @@ -278,13 +289,17 @@ public class ProxyConnectionTest { connection.connect(); assertTrue(connection.isConnected()); - assertTrue(serverHandshakeDone.await(3, TimeUnit.SECONDS)); + assertTrue(serverHandshakeDone.await(5, TimeUnit.SECONDS)); connection.disconnect(); } finally { if (origHost != null) System.setProperty("http.proxyHost", origHost); else System.clearProperty("http.proxyHost"); if (origPort != null) System.setProperty("http.proxyPort", origPort); else System.clearProperty("http.proxyPort"); + if (origSocksHost != null) System.setProperty("socksProxyHost", origSocksHost); + else System.clearProperty("socksProxyHost"); + if (origSocksPort != null) System.setProperty("socksProxyPort", origSocksPort); + else System.clearProperty("socksProxyPort"); } } } diff --git a/test_all.sh b/test_all.sh index 57601f2..59a9ec9 100755 --- a/test_all.sh +++ b/test_all.sh @@ -83,7 +83,7 @@ if [ -f "$JUNIT_JAR" ] && [ -s "$JUNIT_JAR" ]; then rm -f "$BUILD_DIR/test_sources.txt" echo "Executing JUnit tests..." - "$JAVA_BIN" -Djava.awt.headless=true -jar "$JUNIT_JAR" \ + "$JAVA_BIN" -Djava.awt.headless=true -jar "$JUNIT_JAR" execute \ --class-path "$BUILD_DIR/lib3270j:$BUILD_DIR/j3270:$TEST_BUILD_DIR" \ --scan-class-path \ --reports-dir="$REPORTS_DIR"