Skip to content
Snippets Groups Projects
Commit c042537b authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

SW-415: use same setup and teardown as in t_lsmrapp_specification_functional....

SW-415: use same setup and teardown as in t_lsmrapp_specification_functional. TODO: create common bash file with setup/teardown routines.
parent cf6e0b20
No related branches found
No related tags found
1 merge request!87Lsmr epic
#!/bin/sh
#!/bin/bash
set +x
echo "---"
echo "! This requires a running Postgres instance with a configured database according to the settings.py configuration."
echo "! You can run the lsmr_testdatabase command to fire up a temporary instance."
echo "---"
mkdir -p ~/.lofar/dbcredentials
DJANGO_TEST_DATABASE_NAME="lsmr_test_`uuidgen | sed 's/-/_/g'`"
CREDENTIALS_PATH="$HOME/.lofar/dbcredentials/$DJANGO_TEST_DATABASE_NAME.ini"
echo "creating test credentials file: $CREDENTIALS_PATH"
echo "[database:$DJANGO_TEST_DATABASE_NAME]
host=localhost
type=postgres
database=$DJANGO_TEST_DATABASE_NAME
port=7654
user=lsrm
password=lsrm
" > "$CREDENTIALS_PATH"
#keep track of helper application pids to kill in teardown
PIDS=
# setup propagation of signals to child processes
teardown() {
echo "tearing down test environment"
for PID in $PIDS
do
# get the full command
CMD="`ps --pid $PID h -o command`"
echo "killing helper application: $CMD"
# and kill it
kill -TERM $PID
done
echo "removing test credentials file: $CREDENTIALS_PATH"
rm $CREDENTIALS_PATH
}
## Trap upon signals and upon normal exit.
trap 'STATUS=$?; teardown; exit $STATUS' SIGHUP SIGINT SIGQUIT SIGKILL SIGTERM
# fire up a postgres test database
lsmr_testdatabase -C $DJANGO_TEST_DATABASE_NAME &
PIDS="$! $PIDS"
sleep 5
echo "Started Django test database server\n\n"
# Run Django test instance
PORT=8777
lsmr -p $PORT &
DJANGO_PID=$!
echo "Started Django server with PID: " $DJANGO_PID
sleep 15
DJANGO_TEST_PORT=8777
lsmr -p $DJANGO_TEST_PORT -C $DJANGO_TEST_DATABASE_NAME &
PIDS="$! $PIDS"
sleep 5
echo "Started lsmr django server\n\n"
export DJANGO_TEST_PORT=$DJANGO_TEST_PORT
export LSMR_DBCREDENTIALS=$DJANGO_TEST_DATABASE_NAME
# Run test
./t_lsmrapp_scheduling_functional.py
EXITCODE=$?
./t_lsmrapp_scheduling_functional.py &
TEST_PID=$!
PIDS="$TEST_PID $PIDS"
wait "$TEST_PID"
# wait again (to get the status code of the test)
wait "$TEST_PID"
TEST_EXIT_CODE=$?
# Kill Django test instance
pkill -f "lofar/sas/lsmr/manage.py runserver 0.0.0.0:$PORT"
kill $DJANGO_PID
teardown
# Return with success or failure of actual test
exit $EXITCODE
exit $TEST_EXIT_CODE
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment