Adding database update lock support to the test setup/teardown files

- Legacy-Id: 334
This commit is contained in:
Henrik Levkowetz 2007-06-12 16:21:25 +00:00
parent c4cee402d5
commit f1251ca2d6
3 changed files with 30 additions and 1 deletions

View file

@ -10,6 +10,7 @@ function err() {
echo "$program: Error: $*" 1>&2;
exit 2
}
alias die='err'
function warn() {
echo "$program: Warning: $*" 1>&2;

View file

@ -47,9 +47,32 @@ say "Setting up the Django settings for the test suite"
cd $build
settings_local=$(py_module_file "settings_local")
[ "$settings_local" ] || err
[ "$settings_local" ] || die "No setting_local file available"
cat $settings_local test/settings_local_test.py > ietf/settings_local.py
# Acquire lock, to prevent running test and database update at the same time
LOCKDIR=$build/test/update-db.lock
PIDFILE=$build/test/update-db.lock/pid
while true; do
if mkdir $build/test/update-db.lock; then
echo "$$" > $PIDFILE
break
else
pid=$(< $PIDFILE ) || die "Couldn't read pidfile '$PIDFILE'"
if kill -0 $pid; then
echo "Pidfile for process $pid exists, and process is running. Sleeping."
sleep 10
else
echo "Pidfile for process $pid exists, but process isn't running."
echo "Removing lock and old pid file $pidfile."
rm -rf $LOCKDIR
break
fi
fi
done
exit $warnings

View file

@ -19,4 +19,9 @@ if echo "show databases;" | python ietf/manage.py dbshell | grep test_ietf; then
echo "test database removed."
fi
# Release database update lock
LOCKDIR=$build/test/update-db.lock
rm -rf $LOCKDIR
exit $warnings