From f1251ca2d660c01b155e2cd7d53516c6cc5cfeaf Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Tue, 12 Jun 2007 16:21:25 +0000 Subject: [PATCH] Adding database update lock support to the test setup/teardown files - Legacy-Id: 334 --- test/shell-utils | 1 + test/test-setup | 25 ++++++++++++++++++++++++- test/test-teardown | 5 +++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/test/shell-utils b/test/shell-utils index 9a7cd8eaf..7287b060f 100644 --- a/test/shell-utils +++ b/test/shell-utils @@ -10,6 +10,7 @@ function err() { echo "$program: Error: $*" 1>&2; exit 2 } +alias die='err' function warn() { echo "$program: Warning: $*" 1>&2; diff --git a/test/test-setup b/test/test-setup index af130f27d..763087e42 100755 --- a/test/test-setup +++ b/test/test-setup @@ -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 diff --git a/test/test-teardown b/test/test-teardown index 4265cce78..95af46b9a 100755 --- a/test/test-teardown +++ b/test/test-teardown @@ -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