This is an automated email from the ASF dual-hosted git repository. jungm pushed a commit to branch ee11 in repository https://gitbox.apache.org/repos/asf/tomee-tck.git
commit 785e52e0ed8fe75112958e162963da018a4001b0 Author: Markus Jung <[email protected]> AuthorDate: Sun Jul 19 01:47:48 2026 +0200 Guard the self-provisioned TomEE runners against a foreign server on the port --- Jenkinsfile | 1 + environment/tomee/require-tomee-ports-free.sh | 49 +++++++++++++++++++++++++++ runner-standalone/faces-old/pom.xml | 22 ++++++++++++ runner-standalone/transactions/pom.xml | 22 ++++++++++++ 4 files changed, 94 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 52e2526..dc0fcb0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -36,6 +36,7 @@ pipeline { sh -n environment/reset-generated-test-environment.sh sh -n environment/database/require-derby-port-free.sh sh -n environment/database/wait-for-derby.sh + sh -n environment/tomee/require-tomee-ports-free.sh sh -n environment/certificates/generate-test-certificates.sh sh -n runner-webprofile/run-platform-suite.sh sh -n runner-standalone/run-standalone-suite.sh diff --git a/environment/tomee/require-tomee-ports-free.sh b/environment/tomee/require-tomee-ports-free.sh new file mode 100755 index 0000000..929eb9c --- /dev/null +++ b/environment/tomee/require-tomee-ports-free.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0. + +# Refuses to start when any TomEE port is already bound. The Arquillian +# adapter (and a plain socket wait) silently attaches to whatever already +# answers on the port, so a foreign server left on 8080 makes a runner look +# green without ever exercising the TomEE under test. Mirrors +# environment/database/require-derby-port-free.sh for the container ports. +# +# require-tomee-ports-free.sh <http-port> [https-port] [shutdown-port] + +set -eu + +busy=0 + +# A connect that succeeds means something already listens on the port. Prefer +# nc, fall back to bash's /dev/tcp; both are present on the CI agents. +port_in_use() { + port=$1 + if command -v nc >/dev/null 2>&1; then + nc -z localhost "$port" >/dev/null 2>&1 + else + (exec 3<>"/dev/tcp/localhost/$port") 2>/dev/null && exec 3>&- 3<&- + fi +} + +check_port() { + name=$1 + port=$2 + [ -n "$port" ] || return 0 + if port_in_use "$port"; then + echo "Refusing to start: the $name port localhost:$port is already bound" >&2 + busy=1 + else + echo "TomEE $name port localhost:$port is available" + fi +} + +check_port "HTTP" "${1:?usage: require-tomee-ports-free.sh <http-port> [https-port] [shutdown-port]}" +check_port "HTTPS" "${2:-}" +check_port "shutdown" "${3:-}" + +if [ "$busy" -ne 0 ]; then + exit 1 +fi diff --git a/runner-standalone/faces-old/pom.xml b/runner-standalone/faces-old/pom.xml index a6bc6cd..5b0aa51 100644 --- a/runner-standalone/faces-old/pom.xml +++ b/runner-standalone/faces-old/pom.xml @@ -256,6 +256,17 @@ <fileset dir="${tomee.home}/bin" includes="*.sh"/> </chmod> + <!-- Fail fast if any container port is already bound: the + waitfor below only proves *something* answers on the HTTP + port, and a foreign server left on 8080 would let this + suite deploy against and test the wrong container. --> + <exec executable="sh" failonerror="true"> + <arg value="${maven.multiModuleProjectDirectory}/environment/tomee/require-tomee-ports-free.sh"/> + <arg value="${tomee.http.port}"/> + <arg value="${tomee.https.port}"/> + <arg value="${tomee.shutdown.port}"/> + </exec> + <exec executable="${tomee.home}/bin/catalina.sh" failonerror="true"> <arg value="start"/> <env key="JAVA_HOME" value="${java.home}"/> @@ -266,6 +277,17 @@ <fail message="TomEE did not open port ${tomee.http.port} within 180s"> <condition><isset property="tomee.start.timeout"/></condition> </fail> + <!-- Confirm the container that answered is the TomEE this + module just started, bound to the expected HTTP port, + rather than a pre-existing server the port pre-check + could not have seen from a race. --> + <waitfor maxwait="60" maxwaitunit="second" timeoutproperty="tomee.connector.timeout"> + <resourcecontains resource="${tomee.home}/logs/catalina.out" + substring="Starting ProtocolHandler ["http-nio-${tomee.http.port}"]"/> + </waitfor> + <fail message="Started TomEE did not report its HTTP connector on port ${tomee.http.port}; see ${tomee.home}/logs/catalina.out"> + <condition><isset property="tomee.connector.timeout"/></condition> + </fail> <!-- Deploy a single test directory... --> <sequential if:set="tck.test"> diff --git a/runner-standalone/transactions/pom.xml b/runner-standalone/transactions/pom.xml index fc9d1ab..5a7cf6a 100644 --- a/runner-standalone/transactions/pom.xml +++ b/runner-standalone/transactions/pom.xml @@ -256,6 +256,17 @@ <zipfileset src="${tck.home}/dist/com/sun/ts/tests/signaturetest/jta/JTASigTest_jsp_vehicle_web.war" excludes="WEB-INF/lib/sigtest.jar"/> </zip> + <!-- Fail fast if any container port is already bound: the + waitfor below only proves *something* answers on the HTTP + port, and a foreign server left on 8080 would let this + suite deploy against and test the wrong container. --> + <exec executable="sh" failonerror="true"> + <arg value="${maven.multiModuleProjectDirectory}/environment/tomee/require-tomee-ports-free.sh"/> + <arg value="${tomee.http.port}"/> + <arg value="${tomee.https.port}"/> + <arg value="${tomee.shutdown.port}"/> + </exec> + <exec executable="${tomee.home}/bin/catalina.sh" failonerror="true"> <arg value="start"/> <env key="JAVA_HOME" value="${java.home}"/> @@ -266,6 +277,17 @@ <fail message="TomEE did not open port ${tomee.http.port} within 180s"> <condition><isset property="tomee.start.timeout"/></condition> </fail> + <!-- Confirm the container that answered is the TomEE this + module just started, bound to the expected HTTP port, + rather than a pre-existing server the port pre-check + could not have seen from a race. --> + <waitfor maxwait="60" maxwaitunit="second" timeoutproperty="tomee.connector.timeout"> + <resourcecontains resource="${tomee.home}/logs/catalina.out" + substring="Starting ProtocolHandler ["http-nio-${tomee.http.port}"]"/> + </waitfor> + <fail message="Started TomEE did not report its HTTP connector on port ${tomee.http.port}; see ${tomee.home}/logs/catalina.out"> + <condition><isset property="tomee.connector.timeout"/></condition> + </fail> </target> </configuration> </execution>
