pad.pub0.org/tests/frontend/travis/runnerLoadTest.sh

52 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
pecho() { printf %s\\n "$*"; }
log() { pecho "$@"; }
error() { log "ERROR: $@" >&2; }
fatal() { error "$@"; exit 1; }
try() { "$@" || fatal "'$@' failed"; }
MY_DIR=$(try cd "${0%/*}" && try pwd) || exit 1
# reliably move to the etherpad base folder before running it
try cd "${MY_DIR}/../../../"
try sed -e '
s!"loadTest":[^,]*!"loadTest": true!
# Reduce rate limit aggressiveness
s!"points":[^,]*!"points": 1000!
' settings.json.template >settings.json
log "Assuming bin/installDeps.sh has already been run"
node node_modules/ep_etherpad-lite/node/server.js "${@}" >/dev/null &
ep_pid=$!
log "Waiting for Etherpad to accept connections (http://localhost:9001)..."
connected=false
can_connect() {
curl -sSfo /dev/null http://localhost:9001/ || return 1
connected=true
}
now() { date +%s; }
start=$(now)
while [ $(($(now) - $start)) -le 15 ] && ! can_connect; do
sleep 1
done
[ "$connected" = true ] \
|| fatal "Timed out waiting for Etherpad to accept connections"
log "Successfully connected to Etherpad on http://localhost:9001"
# Build the minified files
try 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
log "Running the load tests..."
etherpad-loadtest -d 25
exit_code=$?
kill "$ep_pid" && wait "$ep_pid"
log "Done."
exit "$exit_code"