diff options
| author | Diego Pino Garcia <dpino@igalia.com> | 2021-01-28 16:39:59 +0800 |
|---|---|---|
| committer | Patrick Griffis <tingping@tingping.se> | 2021-04-13 21:14:37 +0000 |
| commit | af867b203176809df2458d77abcf9fd76900822d (patch) | |
| tree | f124e211064329de9b00dbd4ac0c73a031a77907 | |
| parent | 8c260020c8a1fca478c67ae511cbe11d43ddc6be (diff) | |
| download | libsoup-af867b203176809df2458d77abcf9fd76900822d.tar.gz | |
autobahn-server.sh: refactor code
* Use Autobahn virtualenv (default).
* Check port before starting server, and kill running process if
necessary.
* Expects arguments '--start' and '--stop' to start
and stop the server.
| -rwxr-xr-x | tests/autobahn/autobahn-server.sh | 61 |
1 files changed, 54 insertions, 7 deletions
diff --git a/tests/autobahn/autobahn-server.sh b/tests/autobahn/autobahn-server.sh index b634a767..9596e72b 100755 --- a/tests/autobahn/autobahn-server.sh +++ b/tests/autobahn/autobahn-server.sh @@ -1,4 +1,6 @@ -#!/bin/sh +#!/usr/bin/env bash + +# set -x REPORTS_DIR="${PWD}/reports" @@ -6,9 +8,54 @@ cd "$(dirname "$0")" [ ! -d "${REPORTS_DIR}" ] && mkdir "${REPORTS_DIR}" -docker run -it --rm \ - -v "${PWD}:/config" \ - -v "${REPORTS_DIR}:/reports" \ - -p 9001:9001 \ - --name fuzzingserver \ - crossbario/autobahn-testsuite +ACTION=${1:---start} +PORT=${2:-9001} + +autobahn_pid() { + echo $(lsof -i:$PORT | tail -1 | awk '{ print $2 }') +} + +ensure_autobahn_is_not_running() { + local pid=$(autobahn_pid) + if [[ $pid -gt 0 ]]; then + autobahn_stop + pid=$(autobahn_pid) + if [[ $pid -gt 0 ]]; then + echo "Cannot start autobahn server: $PORT already in use" + exit 1 + fi + fi +} + +autobahn_start() { + ensure_autobahn_is_not_running + + if [[ -n "${USE_DOCKER}" ]]; then + docker run -it --rm \ + -v "${PWD}:/config" \ + -v "${REPORTS_DIR}:/reports" \ + -p $PORT:$PORT \ + --name fuzzingserver \ + crossbario/autobahn-testsuite + else + virtualenv ~/wstest + wstest -m fuzzingserver &> autobahn-server.log + fi +} + +autobahn_stop() { + local pid=$(autobahn_pid) + kill $pid &> /dev/null +} + +case "$ACTION" in + "--start") + autobahn_start + ;; + "--stop") + autobahn_stop + ;; + *) + echo "Unknown argument: $ACTION" + exit 1 +esac |
