diff --git a/Jenkinsfile b/Jenkinsfile index af6b11561..ba5118aea 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -45,7 +45,12 @@ def runStages() { } stage("REST test suite") { - sh "./tests/simulation/restapi.sh --data-dir resttest0_data --base-port \$(( 9100 + EXECUTOR_NUMBER * 100 )) --base-rest-port \$(( 7100 + EXECUTOR_NUMBER * 100 )) --base-metrics-port \$(( 8108 + EXECUTOR_NUMBER * 100 )) --sleep-timeout 30" + sh """#!/bin/bash + set -e + ./tests/simulation/restapi.sh --data-dir resttest0_data --base-port \$(( 9100 + EXECUTOR_NUMBER * 100 )) \ + --base-rest-port \$(( 7100 + EXECUTOR_NUMBER * 100 )) --base-metrics-port \ + \$(( 8108 + EXECUTOR_NUMBER * 100 )) --sleep-timeout 30 --kill-old-processes + """ } stage("Testnet finalization") { diff --git a/scripts/launch_local_testnet.sh b/scripts/launch_local_testnet.sh index aff1cd65e..60e980c34 100755 --- a/scripts/launch_local_testnet.sh +++ b/scripts/launch_local_testnet.sh @@ -315,6 +315,12 @@ cleanup() { sleep 2 pkill -f -9 -P $$ nimbus_beacon_node &>/dev/null || true pkill -f -9 -P $$ nimbus_validator_client &>/dev/null || true + + # Delete the binaries we just built, because these are unusable outside this + # local testnet. + for BINARY in ${BINARIES}; do + rm build/${BINARY} + done } trap 'cleanup' SIGINT SIGTERM EXIT diff --git a/tests/simulation/restapi.sh b/tests/simulation/restapi.sh index 4b0c2f49b..5c0ce5f3a 100755 --- a/tests/simulation/restapi.sh +++ b/tests/simulation/restapi.sh @@ -8,6 +8,7 @@ BASE_METRICS_PORT="48008" BASE_REST_PORT="47000" TIMEOUT_DURATION="30" TEST_DIRNAME="resttest0_data" +KILL_OLD_PROCESSES="0" #################### # argument parsing # @@ -27,7 +28,7 @@ if [ ${PIPESTATUS[0]} != 4 ]; then fi OPTS="h" -LONGOPTS="help,data-dir:,base-port:,base-rest-port:,base-metrics-port:,sleep-timeout:" +LONGOPTS="help,data-dir:,base-port:,base-rest-port:,base-metrics-port:,sleep-timeout:,kill-old-processes" print_help() { cat </dev/null || { echo "'lsof' not installed. Aborting."; exit 1; } +for PORT in ${BASE_PORT} ${BASE_METRICS_PORT} ${BASE_REST_PORT}; do + for PID in $(lsof -n -i tcp:${PORT} -sTCP:LISTEN -t); do + echo -n "Found old process listening on port ${PORT}, with PID ${PID}. " + if [[ "${KILL_OLD_PROCESSES}" == "1" ]]; then + echo "Killing it." + kill -9 ${PID} || true + else + echo "Aborting." + exit 1 + fi + done +done + build_if_missing () { if [[ ! -e "${GIT_ROOT}/build/${1}" ]]; then ${MAKE} -C "${GIT_ROOT}" -j ${NPROC} ${1}