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
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"