blob: 4f3f7ad6f748b19c39ea12688449ecd1bc0f9228 [file] [log] [blame]
Neels Hofmeyrdae3d3c2017-03-28 12:16:58 +02001#!/bin/sh
Neels Hofmeyr936a81e2017-09-14 01:31:41 +02002
3echo 'creating files'
Neels Hofmeyr417a03d2017-05-04 14:48:49 +02004dir="$(mktemp -d)"
5n1="long name"
6f1="$dir/$n1"
7touch "$f1"
8n2="shorter"
9f2="$dir/$n2"
10touch "$f2"
11sync
Neels Hofmeyr936a81e2017-09-14 01:31:41 +020012
13echo 'launch a program that locks a given file, it will create $dir/lock_test'
Neels Hofmeyr417a03d2017-05-04 14:48:49 +020014python3 ./lock_test_help.py "$dir" "$n1" &
Neels Hofmeyr936a81e2017-09-14 01:31:41 +020015
16echo 'wait until this lock_test lock file was created by program'
Neels Hofmeyr417a03d2017-05-04 14:48:49 +020017while [ ! -f "$dir/lock_test" ]; do
18 sleep .1
19done
Neels Hofmeyr936a81e2017-09-14 01:31:41 +020020sync
21
22echo 'expecting the lock file to reflect "long name"'
Neels Hofmeyra6278b72017-05-10 13:46:11 +020023echo "launched first, locked by: '$(cat "$dir/lock_test")'"
Neels Hofmeyr936a81e2017-09-14 01:31:41 +020024
25echo 'launching second program, should find the lock intact and wait'
Neels Hofmeyr417a03d2017-05-04 14:48:49 +020026python3 ./lock_test_help.py "$dir" "$n2" &
Neels Hofmeyr936a81e2017-09-14 01:31:41 +020027while [ ! -f "$f2.ready" ]; do
28 sleep .1
29done
30sleep 1
31sync
Neels Hofmeyra6278b72017-05-10 13:46:11 +020032echo "launched second, locked by: '$(cat "$dir/lock_test")'"
Neels Hofmeyr936a81e2017-09-14 01:31:41 +020033
34echo 'drop the first lock, $f1 removal signals the first process to stop locking'
Neels Hofmeyr417a03d2017-05-04 14:48:49 +020035rm "$f1"
Neels Hofmeyr936a81e2017-09-14 01:31:41 +020036
37echo 'wait for first program to carry out the lock release'
Neels Hofmeyr417a03d2017-05-04 14:48:49 +020038while [ ! -f "$f1.done" ]; do
39 sleep .1
40done
Neels Hofmeyr936a81e2017-09-14 01:31:41 +020041
42echo 'now expecting second program to lock'
Neels Hofmeyra6278b72017-05-10 13:46:11 +020043echo "waited, locked by: '$(cat "$dir/lock_test")'"
Neels Hofmeyr936a81e2017-09-14 01:31:41 +020044
45echo 'release the second program also'
Neels Hofmeyr417a03d2017-05-04 14:48:49 +020046rm "$f2"
47while [ ! -f "$f2.done" ]; do
48 sleep .1
49done
Neels Hofmeyr936a81e2017-09-14 01:31:41 +020050
51echo 'expecting the lock to be gone'
Neels Hofmeyra6278b72017-05-10 13:46:11 +020052echo "waited more, locked by: '$(cat "$dir/lock_test")'"
Neels Hofmeyr417a03d2017-05-04 14:48:49 +020053rm -rf "$dir"