From 66aff57d87732b1fdbaea7cdc0c376262fc2f96f Mon Sep 17 00:00:00 2001 From: John McLear Date: Sat, 30 May 2020 18:51:14 +0100 Subject: [PATCH] tests: introduce automated load testing (#4066) --- tests/frontend/travis/runnerBackend.sh | 6 +-- tests/frontend/travis/runnerLoadTest.sh | 52 +++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 3 deletions(-) create mode 100755 tests/frontend/travis/runnerLoadTest.sh diff --git a/tests/frontend/travis/runnerBackend.sh b/tests/frontend/travis/runnerBackend.sh index 3750dc4c8..b782929bc 100755 --- a/tests/frontend/travis/runnerBackend.sh +++ b/tests/frontend/travis/runnerBackend.sh @@ -28,15 +28,15 @@ echo "Now I will try for 15 seconds to connect to Etherpad on http://localhost:9 echo "Successfully connected to Etherpad on http://localhost:9001" +# a copy of settings.json is necessary for the backend tests to work +cp settings.json.template settings.json + # Build the minified files? curl http://localhost:9001/p/minifyme -f -s > /dev/null # just in case, let's wait for another 10 seconds before going on sleep 10 -# a copy of settings.json is necessary for the backend tests to work -cp settings.json.template settings.json - # run the backend tests echo "Now run the backend tests" cd src diff --git a/tests/frontend/travis/runnerLoadTest.sh b/tests/frontend/travis/runnerLoadTest.sh new file mode 100755 index 000000000..b4d85335a --- /dev/null +++ b/tests/frontend/travis/runnerLoadTest.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# do not continue if there is an error +set -eu + +# source: https://stackoverflow.com/questions/59895/get-the-source-directory-of-a-bash-script-from-within-the-script-itself#246128 +MY_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" + +# reliably move to the etherpad base folder before running it +cd "${MY_DIR}/../../../" + +# start Etherpad, assuming all dependencies are already installed. +# +# This is possible because the "install" section of .travis.yml already contains +# a call to bin/installDeps.sh +echo "Running Etherpad directly, assuming bin/installDeps.sh has already been run" +node node_modules/ep_etherpad-lite/node/server.js "${@}" > /dev/null & + +echo "Now I will try for 15 seconds to connect to Etherpad on http://localhost:9001" + +# wait for at most 15 seconds until Etherpad starts accepting connections +# +# modified from: +# https://unix.stackexchange.com/questions/5277/how-do-i-tell-a-script-to-wait-for-a-process-to-start-accepting-requests-on-a-po#349138 +# +(timeout 15 bash -c 'until echo > /dev/tcp/localhost/9001; do sleep 0.5; done') || \ + (echo "Could not connect to Etherpad on http://localhost:9001" ; exit 1) + +echo "Successfully connected to Etherpad on http://localhost:9001" + +# a copy of settings.json is necessary for the backend tests to work +cp settings.json.template settings.json + +# Build the minified files? +curl http://localhost:9001/p/minifyme -f -s > /dev/null + +# just in case, let's wait for another 10 seconds before going on +sleep 10 + +# run the backend tests +echo "Now run the backend tests" +cd etherpad-load-test +npm install +node app.js +# cd src +# npm run test +exit_code=$? + +kill $! +sleep 5 + +exit $exit_code