Skip to content

Commit f1251ca

Browse files
committed
Adding database update lock support to the test setup/teardown files
- Legacy-Id: 334
1 parent c4cee40 commit f1251ca

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

test/shell-utils

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function err() {
1010
echo "$program: Error: $*" 1>&2;
1111
exit 2
1212
}
13+
alias die='err'
1314

1415
function warn() {
1516
echo "$program: Warning: $*" 1>&2;

test/test-setup

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,32 @@ say "Setting up the Django settings for the test suite"
4747
cd $build
4848

4949
settings_local=$(py_module_file "settings_local")
50-
[ "$settings_local" ] || err
50+
[ "$settings_local" ] || die "No setting_local file available"
5151

5252
cat $settings_local test/settings_local_test.py > ietf/settings_local.py
5353

54+
# Acquire lock, to prevent running test and database update at the same time
55+
56+
LOCKDIR=$build/test/update-db.lock
57+
PIDFILE=$build/test/update-db.lock/pid
58+
59+
while true; do
60+
if mkdir $build/test/update-db.lock; then
61+
echo "$$" > $PIDFILE
62+
break
63+
else
64+
pid=$(< $PIDFILE ) || die "Couldn't read pidfile '$PIDFILE'"
65+
if kill -0 $pid; then
66+
echo "Pidfile for process $pid exists, and process is running. Sleeping."
67+
sleep 10
68+
else
69+
echo "Pidfile for process $pid exists, but process isn't running."
70+
echo "Removing lock and old pid file $pidfile."
71+
rm -rf $LOCKDIR
72+
break
73+
fi
74+
fi
75+
done
76+
5477

5578
exit $warnings

test/test-teardown

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ if echo "show databases;" | python ietf/manage.py dbshell | grep test_ietf; then
1919
echo "test database removed."
2020
fi
2121

22+
# Release database update lock
23+
24+
LOCKDIR=$build/test/update-db.lock
25+
rm -rf $LOCKDIR
26+
2227
exit $warnings

0 commit comments

Comments
 (0)