Commit 823471fa authored by Aaron Barnes's avatar Aaron Barnes Committed by Gerrit Code Review
Browse files

test/behat/mahara_behat.sh: Shutdown background processes on error

Change-Id: Ibf0b51787d544ebfd72e1e6e9e092c7d5da0fdc5
parent a596b554
......@@ -3,6 +3,12 @@
# Quit on error
set -e
# Get action and Mahara dir
ACTION=$1
SCRIPTPATH=`readlink -f "${BASH_SOURCE[0]}"`
MAHARAROOT=`dirname $( dirname $( dirname "$SCRIPTPATH" ))`
SERVER=0
function is_selenium_running {
res=$(curl -o /dev/null --silent --write-out '%{http_code}\n' http://localhost:4444/wd/hub/status)
if [[ $res == "200" ]]; then
......@@ -12,6 +18,24 @@ function is_selenium_running {
fi
}
function cleanup {
echo "Shutdown Selenium"
curl -o /dev/null --silent http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer
if [[ $SERVER ]]
then
echo "Shutdown PHP server"
kill $SERVER
fi
if [[ $1 ]]
then
exit $1
else
exit 255
fi
}
# Check we are not running as root for some weird reason
if [[ "$USER" = "root" ]]
then
......@@ -19,13 +43,12 @@ then
exit 1
fi
# Get action and Mahara dir
ACTION=$1
SCRIPTPATH=`readlink -f "${BASH_SOURCE[0]}"`
MAHARAROOT=`dirname $( dirname $( dirname "$SCRIPTPATH" ))`
cd $MAHARAROOT
# Trap errors so we can cleanup
trap cleanup ERR
trap cleanup INT
if [ "$ACTION" = "action" ]
then
......@@ -82,7 +105,7 @@ then
fi
echo "Start PHP server"
php --server localhost:8000 --docroot ./htdocs &>/dev/null &
php --server localhost:8000 --docroot $MAHARAROOT/htdocs &>/dev/null &
SERVER=$!
echo "Enable test site"
......@@ -113,11 +136,7 @@ then
echo "=================================================="
echo
echo "Shutdown"
# Kill Selenium
curl -o /dev/null --silent http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer
# Kill PHP server
kill $SERVER
cleanup 0
else
# Help text if we got an unexpected (or empty) first param
echo "Expected something like one of the following:"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment