ci: isolate s3 test runner state (#3180)

This commit is contained in:
安正超
2026-06-02 22:40:37 +08:00
committed by GitHub
parent a55ead42e7
commit 7cc730d9c0
6 changed files with 71 additions and 73 deletions
+10 -48
View File
@@ -13,8 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# Cleanup script for port 9000 and test data directory
# This script kills any process using port 9000 and cleans the test data directory
# Cleanup script for the local s3-tests data directory.
# It reports port usage but does not kill unrelated processes.
set -euo pipefail
@@ -22,7 +22,6 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
DATA_DIR="${PROJECT_ROOT}/target/test-data/rustfs-single"
PORT="${S3_PORT:-9000}"
HOST="${S3_HOST:-127.0.0.1}"
log_info() {
echo "[INFO] $*"
@@ -32,17 +31,16 @@ log_warn() {
echo "[WARN] $*"
}
cleanup_port_9000() {
check_port_usage() {
log_info "Checking for processes using port ${PORT}..."
# Try to find process using port 9000
PID=""
# Try lsof first (works on macOS and Linux)
if command -v lsof >/dev/null 2>&1; then
PID=$(lsof -ti:${PORT} 2>/dev/null || true)
fi
# Fallback: try using netstat or ss
if [ -z "$PID" ]; then
if command -v netstat >/dev/null 2>&1; then
@@ -51,49 +49,13 @@ cleanup_port_9000() {
PID=$(ss -tuln 2>/dev/null | grep ":${PORT} " | awk '{print $6}' | cut -d',' -f2 | cut -d'=' -f2 | head -1 || true)
fi
fi
# If we found a PID, kill it
if [ -n "$PID" ] && [ "$PID" != "-" ]; then
log_info "Found process ${PID} using port ${PORT}, killing it..."
kill -9 "$PID" 2>/dev/null || true
sleep 2
# Verify the process is gone
if kill -0 "$PID" 2>/dev/null; then
log_warn "Process ${PID} is still running, trying force kill..."
kill -9 "$PID" 2>/dev/null || true
sleep 1
fi
log_warn "Port ${PORT} is in use by PID(s): ${PID}"
log_warn "Not killing unrelated processes; stop the owner manually or use another S3_PORT."
else
log_info "No process found using port ${PORT}"
fi
# Also try to kill any rustfs processes (more aggressive cleanup)
if pgrep -f "rustfs.*${PORT}" >/dev/null 2>&1; then
log_info "Killing any remaining rustfs processes using port ${PORT}..."
pkill -f "rustfs.*${PORT}" 2>/dev/null || true
sleep 1
fi
# Verify port is released
log_info "Verifying port ${PORT} is released..."
for i in {1..10}; do
if command -v nc >/dev/null 2>&1; then
if ! nc -z "${HOST}" "${PORT}" 2>/dev/null; then
log_info "Port ${PORT} is now available"
break
fi
elif timeout 1 bash -c "cat < /dev/null > /dev/tcp/${HOST}/${PORT}" 2>/dev/null; then
# Port is still in use
if [ $i -eq 10 ]; then
log_warn "Port ${PORT} may still be in use after cleanup attempts"
fi
else
log_info "Port ${PORT} is now available"
break
fi
sleep 1
done
}
cleanup_data_directory() {
@@ -120,7 +82,7 @@ cleanup_data_directory() {
main() {
log_info "Starting cleanup..."
cleanup_port_9000
check_port_usage
cleanup_data_directory
log_info "Cleanup completed"
}