aboutsummaryrefslogtreecommitdiffstats
path: root/selftest
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2017-05-04 14:48:49 +0200
committerNeels Hofmeyr <neels@hofmeyr.de>2017-05-04 14:53:46 +0200
commit417a03df3a142f88b386568084d05a071f4f49a7 (patch)
tree37c6b3ecc4be0f009d5d077a5bae3231932d0ef8 /selftest
parent96ed9ab14d16849a66636f8f080cfa726d9c6a46 (diff)
lock_test: make more robust
Before, the test would rely on timeouts to work out. Instead, use marker files to indicate whether to wait longer. Firstly to signal a blocking process should end, secondly that it has indeed ended. Also use a mktemp tempdir instead of /tmp
Diffstat (limited to 'selftest')
-rw-r--r--selftest/lock_test.ok8
-rwxr-xr-xselftest/lock_test.sh35
-rw-r--r--selftest/lock_test_help.py14
3 files changed, 41 insertions, 16 deletions
diff --git a/selftest/lock_test.ok b/selftest/lock_test.ok
index 2c0f31b..0e3db40 100644
--- a/selftest/lock_test.ok
+++ b/selftest/lock_test.ok
@@ -1,7 +1,7 @@
-acquired lock: 'long_name'
-launched first, locked by: long_name
-launched second, locked by: long_name
-leaving lock: 'long_name'
+acquired lock: 'long name'
+launched first, locked by: long name
+launched second, locked by: long name
+leaving lock: 'long name'
acquired lock: 'shorter'
waited, locked by: shorter
leaving lock: 'shorter'
diff --git a/selftest/lock_test.sh b/selftest/lock_test.sh
index c82d141..ad531eb 100755
--- a/selftest/lock_test.sh
+++ b/selftest/lock_test.sh
@@ -1,10 +1,27 @@
#!/bin/sh
-python3 ./lock_test_help.py long name &
-sleep .2
-echo "launched first, locked by: $(cat /tmp/lock_test)"
-python3 ./lock_test_help.py shorter &
-echo "launched second, locked by: $(cat /tmp/lock_test)"
-sleep .4
-echo "waited, locked by: $(cat /tmp/lock_test)"
-sleep .5
-echo "waited more, locked by: $(cat /tmp/lock_test)"
+dir="$(mktemp -d)"
+n1="long name"
+f1="$dir/$n1"
+touch "$f1"
+n2="shorter"
+f2="$dir/$n2"
+touch "$f2"
+sync
+python3 ./lock_test_help.py "$dir" "$n1" &
+while [ ! -f "$dir/lock_test" ]; do
+ sleep .1
+done
+echo "launched first, locked by: $(cat "$dir/lock_test")"
+python3 ./lock_test_help.py "$dir" "$n2" &
+echo "launched second, locked by: $(cat "$dir/lock_test")"
+rm "$f1"
+while [ ! -f "$f1.done" ]; do
+ sleep .1
+done
+echo "waited, locked by: $(cat "$dir/lock_test")"
+rm "$f2"
+while [ ! -f "$f2.done" ]; do
+ sleep .1
+done
+echo "waited more, locked by: $(cat "$dir/lock_test")"
+rm -rf "$dir"
diff --git a/selftest/lock_test_help.py b/selftest/lock_test_help.py
index 0549981..7b6dfa1 100644
--- a/selftest/lock_test_help.py
+++ b/selftest/lock_test_help.py
@@ -1,17 +1,25 @@
import sys
import time
+import os
import _prep
-from osmo_gsm_tester.util import FileLock
+from osmo_gsm_tester.util import FileLock, touch_file
-fl = FileLock('/tmp/lock_test', '_'.join(sys.argv[1:]))
+testdir, name = sys.argv[1:]
+stop_signalling_file = os.path.join(testdir, name)
+assert os.path.isfile(stop_signalling_file)
+
+lockfile_path = os.path.join(testdir, 'lock_test')
+fl = FileLock(lockfile_path, name)
with fl:
print('acquired lock: %r' % fl.owner)
sys.stdout.flush()
- time.sleep(0.5)
+ while os.path.exists(stop_signalling_file):
+ time.sleep(.1)
print('leaving lock: %r' % fl.owner)
sys.stdout.flush()
+touch_file(stop_signalling_file + '.done')
# vim: expandtab tabstop=4 shiftwidth=4