From cf079ec1d5d46fbb969c889c456f5326c5e6ffbe Mon Sep 17 00:00:00 2001 From: Konrad Malawski Date: Thu, 3 Dec 2015 14:56:45 +0100 Subject: [PATCH] +htc,tes #18563 move scripts autobahn jenkins scripts to project --- .../autobahn-jenkins/step-1-client-tests.sh | 22 ++++++ .../autobahn-jenkins/step-2-run-sbt-client.sh | 3 + .../step-3-download-client-test-results.sh | 13 ++++ .../step-4-stop-client-tests-server.sh | 4 ++ .../step-5-server-tests-all.sh | 67 +++++++++++++++++++ .../step-6-collect-results.sh | 37 ++++++++++ 6 files changed, 146 insertions(+) create mode 100644 akka-http-core/src/test/scripts/autobahn-jenkins/step-1-client-tests.sh create mode 100644 akka-http-core/src/test/scripts/autobahn-jenkins/step-2-run-sbt-client.sh create mode 100644 akka-http-core/src/test/scripts/autobahn-jenkins/step-3-download-client-test-results.sh create mode 100644 akka-http-core/src/test/scripts/autobahn-jenkins/step-4-stop-client-tests-server.sh create mode 100644 akka-http-core/src/test/scripts/autobahn-jenkins/step-5-server-tests-all.sh create mode 100644 akka-http-core/src/test/scripts/autobahn-jenkins/step-6-collect-results.sh diff --git a/akka-http-core/src/test/scripts/autobahn-jenkins/step-1-client-tests.sh b/akka-http-core/src/test/scripts/autobahn-jenkins/step-1-client-tests.sh new file mode 100644 index 0000000000..7a54c230e6 --- /dev/null +++ b/akka-http-core/src/test/scripts/autobahn-jenkins/step-1-client-tests.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +### CLIENT TESTS ### + +CLIENT_CID=autobahn-client.cid + +echo "~~~ Docker state before running CLIENT tests ~~~" +listeners=docker ps | grep '8080->8080' | wc -l +if [ "$listeners" == "0" ]; then + echo "Docker state OK..." +else + for id in $(docker ps -q); do + docker kill $id; + done +fi + +## RUN CLIENT-SIDE TEST SERVER ## +# TODO technically should be possible to -v mount the reports instead (unsure on directory though) +# this would spare us step-3 +rm -f $CLIENT_CID +docker run -d --cidfile=$CLIENT_CID \ + -p 8080:8080 -p 9001:9001 \ + jrudolph/autobahn-testsuite diff --git a/akka-http-core/src/test/scripts/autobahn-jenkins/step-2-run-sbt-client.sh b/akka-http-core/src/test/scripts/autobahn-jenkins/step-2-run-sbt-client.sh new file mode 100644 index 0000000000..f8b0107c47 --- /dev/null +++ b/akka-http-core/src/test/scripts/autobahn-jenkins/step-2-run-sbt-client.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +## MOCK, use jenkins to run: +# 'akka-http-core-experimental/test:run-main akka.http.impl.engine.ws.WSClientAutobahnTest' \ No newline at end of file diff --git a/akka-http-core/src/test/scripts/autobahn-jenkins/step-3-download-client-test-results.sh b/akka-http-core/src/test/scripts/autobahn-jenkins/step-3-download-client-test-results.sh new file mode 100644 index 0000000000..85c5a77a2b --- /dev/null +++ b/akka-http-core/src/test/scripts/autobahn-jenkins/step-3-download-client-test-results.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +# "download" [client] results from docker container + +rm -rf localhost\:8080/ +echo "Downloading client results report..." +wget --recursive --quiet --page-requisites --html-extension \ + --convert-links --domains localhost --no-parent \ + --directory-prefix=client/ \ + http://localhost:8080/cwd/reports/clients/index.html + +rm -f client/index.json* +wget --quiet --directory-prefix=client/ \ + http://localhost:8080/cwd/reports/clients/index.json diff --git a/akka-http-core/src/test/scripts/autobahn-jenkins/step-4-stop-client-tests-server.sh b/akka-http-core/src/test/scripts/autobahn-jenkins/step-4-stop-client-tests-server.sh new file mode 100644 index 0000000000..2a8a31d916 --- /dev/null +++ b/akka-http-core/src/test/scripts/autobahn-jenkins/step-4-stop-client-tests-server.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +# STOP TEST SERVER (CLIENT TESTS) +docker stop $(cat autobahn-client.cid) +rm -f autobahn-client.cid \ No newline at end of file diff --git a/akka-http-core/src/test/scripts/autobahn-jenkins/step-5-server-tests-all.sh b/akka-http-core/src/test/scripts/autobahn-jenkins/step-5-server-tests-all.sh new file mode 100644 index 0000000000..3d35452bb5 --- /dev/null +++ b/akka-http-core/src/test/scripts/autobahn-jenkins/step-5-server-tests-all.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +### SERVER TESTS ### + +## RUN AKKA WS-ECHO SERVER ## +# sadly hardcoded here, we must do much more than just "run sbt", thus running manually +SBT_JAR=/usr/share/sbt-launcher-packaging/bin/sbt-launch.jar # this jar is "sbt-latest-deb" (from the apt package) +SBT_OPTS="-Dsbt.ivy.home=/localhome/jenkinsakka/.ivy2 -Dsbt.override.repos=false" + +# warning, bash magic – the parens are important, they cause the background process to be executed in a sub shell +# and only thanks to that, will it not be forced into [Stopped] state, as bash thinks sbt is awaiting on some input +# and then decides to stop it (instead of keep it running). Keeping it in a sub shell, keeps it running. +TEST_CLASS=akka.http.impl.engine.ws.WSServerAutobahnTest +(java $SBT_OPTS -Dakka.ws-mode=sleep -Dakka.ws-host=127.0.0.1 -jar $SBT_JAR "akka-http-core-experimental/test:run-main $TEST_CLASS" | tee output &) + +# because of the sub-shell $! is not reported, we need to find the PID some other way: +SUB_PID=$(jps -mlV | grep $TEST_CLASS | awk '{print $1}') # the PID of JVM + + +## PREPARE TCK ## +echo "~~~ Docker state before running SERVER tests ~~~" +listeners=docker ps | grep '8080->8080' | wc -l +if [ "$listeners" == "0" ]; then + echo "Docker state OK..." +else + for id in $(docker ps -q); do + docker kill $id; + done +fi + + +## AWAIT ON SERVER INIT ## +# we need to wait for the server to start (compilation may happen etc, it may take time) +set +x +echo "Awaiting server startup before running tests" +while [ "$(grep 'akka.http.impl.engine.ws.WSServerAutobahnTest' output | wc -l)" == "0" ]; +do + sleep 5 + echo -n '.'; +done +set -x + +# we need to configure the test-client to hit 127.0.0.1 (this works, even from within the container, see below) +echo '{ + "outdir": "/tmp/server-report", + "servers": [ + { + "agent": "AutobahnPython", + "url": "ws://127.0.0.1:9001" + } + ], + "cases": ["*"], + "exclude-cases": [], + "exclude-agent-cases": {} +}' > /tmp/fuzzingclient.json + +## RUN TESTS ## +# net=host allows treating localhost in the container as-if the "hosts" +docker run --net=host \ + --rm=true \ + -v /tmp/fuzzingclient.json:/tmp/fuzzingclient.json \ + -v `pwd`/server-reports:/tmp/server-report \ + jrudolph/autobahn-testsuite-client + +# reports are automatically put to `pwd`/reports, we expose them in jenkins + +# okey, time to shut down the server +kill -9 $SUB_PID \ No newline at end of file diff --git a/akka-http-core/src/test/scripts/autobahn-jenkins/step-6-collect-results.sh b/akka-http-core/src/test/scripts/autobahn-jenkins/step-6-collect-results.sh new file mode 100644 index 0000000000..f236a1158a --- /dev/null +++ b/akka-http-core/src/test/scripts/autobahn-jenkins/step-6-collect-results.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +set +x +RED='\033[0;31m' +GREEN='\033[0;32m' +NC='\033[0m' # No Color + +# FAIL IF CLIENT TESTS FAILED +# one is there because of the example column +client_errors=$(cat client/index.json | grep --ignore-case -n -B1 -A3 '"behavior": "fail' || true) # or true, in order to not fail the build if grep finds no lines +if [ "$(echo $client_errors | wc -c)" -gt "1" ]; +then + echo -e "${RED}[FAILED] WebSocket Client tests failed! See report (you can find it on the left-hand side panel on Jenkins). ${NC}" + echo -e "${RED}[FAILED] Client tests report available: https://jenkins.akka.io:8498/job/akka-http-websockets/$BUILD_NUMBER/Autobahn_TCK_%E2%80%93_WebSocket_Client/ ${NC}" + echo -e "${RED}[FAILED] Summary:" + echo -e "$(cat client/index.json | grep --ignore-case -n -B1 -A3 '"behavior": "fail')" + echo -e "${NC}" + exit -1 +else + echo -e "${GREEN}[PASSED] WebSocket Client tests passed...${NC}" +fi + + +# FAIL IF SERVER TESTS FAILED +server_errors=$(cat reports/index.json | grep --ignore-case -n -B1 -A3 '"behavior": "fail' || true) # or true, in order to not fail the build if grep finds no lines +if [ "$(echo $server_errors | wc -c)" -gt "1" ]; +then + echo -e "${RED}[FAILED] WebSocket Server tests failed! See report (you can find it on the left-hand side panel on Jenkins). ${NC}" + echo -e "${RED}[FAILED] Server tests report available: https://jenkins.akka.io:8498/job/akka-http-websockets/$BUILD_NUMBER/Autobahn_TCK_%E2%80%93_WebSocket_Server/ ${NC}" + echo -e "${RED}[FAILED] Summary:" + echo -e "$(cat reports/index.json | grep --ignore-case -n -B1 -A3 '"behavior": "fail')" + echo -e "${NC}" + exit -1 +else + echo -e "${GREEN}[PASSED] WebSocket Server tests passed...${NC}" +fi + +set -x