Adding database update lock support to the test setup/teardown files
- Legacy-Id: 334
This commit is contained in:
parent
c4cee402d5
commit
f1251ca2d6
|
@ -10,6 +10,7 @@ function err() {
|
||||||
echo "$program: Error: $*" 1>&2;
|
echo "$program: Error: $*" 1>&2;
|
||||||
exit 2
|
exit 2
|
||||||
}
|
}
|
||||||
|
alias die='err'
|
||||||
|
|
||||||
function warn() {
|
function warn() {
|
||||||
echo "$program: Warning: $*" 1>&2;
|
echo "$program: Warning: $*" 1>&2;
|
||||||
|
|
|
@ -47,9 +47,32 @@ say "Setting up the Django settings for the test suite"
|
||||||
cd $build
|
cd $build
|
||||||
|
|
||||||
settings_local=$(py_module_file "settings_local")
|
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
|
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
|
exit $warnings
|
||||||
|
|
|
@ -19,4 +19,9 @@ if echo "show databases;" | python ietf/manage.py dbshell | grep test_ietf; then
|
||||||
echo "test database removed."
|
echo "test database removed."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Release database update lock
|
||||||
|
|
||||||
|
LOCKDIR=$build/test/update-db.lock
|
||||||
|
rm -rf $LOCKDIR
|
||||||
|
|
||||||
exit $warnings
|
exit $warnings
|
||||||
|
|
Loading…
Reference in a new issue