[libsoup/autobahn-integration-new: 8/21] autobahn-server.sh: refactor code




commit 789cad6ed92508eb4bc3b0e4d442aee77bf0bd0d
Author: Diego Pino Garcia <dpino igalia com>
Date:   Thu Jan 28 16:39:59 2021 +0800

    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.

 tests/autobahn/autobahn-server.sh | 61 ++++++++++++++++++++++++++++++++++-----
 1 file 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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]