blob: 9e4f44a9846749b7629a7da20ab64ba87ba2cf39 [file] [log] [blame]
Neels Hofmeyrdae3d3c2017-03-28 12:16:58 +02001#!/bin/sh
Neels Hofmeyr936a81e2017-09-14 01:31:41 +02002
Pau Espin Pedrolab1904a2020-05-06 18:35:26 +02003owndir="$(dirname -- "$0")"
4
Neels Hofmeyr936a81e2017-09-14 01:31:41 +02005echo 'creating files'
Neels Hofmeyr417a03d2017-05-04 14:48:49 +02006dir="$(mktemp -d)"
7n1="long name"
8f1="$dir/$n1"
9touch "$f1"
10n2="shorter"
11f2="$dir/$n2"
12touch "$f2"
13sync
Neels Hofmeyr936a81e2017-09-14 01:31:41 +020014
15echo 'launch a program that locks a given file, it will create $dir/lock_test'
Pau Espin Pedrolab1904a2020-05-06 18:35:26 +020016python3 $owndir/lock_test_help.py "$dir" "$n1" &
Neels Hofmeyr936a81e2017-09-14 01:31:41 +020017
18echo 'wait until this lock_test lock file was created by program'
Neels Hofmeyr417a03d2017-05-04 14:48:49 +020019while [ ! -f "$dir/lock_test" ]; do
20 sleep .1
21done
Neels Hofmeyr936a81e2017-09-14 01:31:41 +020022sync
23
24echo 'expecting the lock file to reflect "long name"'
Neels Hofmeyra6278b72017-05-10 13:46:11 +020025echo "launched first, locked by: '$(cat "$dir/lock_test")'"
Neels Hofmeyr936a81e2017-09-14 01:31:41 +020026
27echo 'launching second program, should find the lock intact and wait'
Pau Espin Pedrolab1904a2020-05-06 18:35:26 +020028python3 $owndir/lock_test_help.py "$dir" "$n2" &
Neels Hofmeyr936a81e2017-09-14 01:31:41 +020029while [ ! -f "$f2.ready" ]; do
30 sleep .1
31done
32sleep 1
33sync
Neels Hofmeyra6278b72017-05-10 13:46:11 +020034echo "launched second, locked by: '$(cat "$dir/lock_test")'"
Neels Hofmeyr936a81e2017-09-14 01:31:41 +020035
36echo 'drop the first lock, $f1 removal signals the first process to stop locking'
Neels Hofmeyr417a03d2017-05-04 14:48:49 +020037rm "$f1"
Neels Hofmeyr936a81e2017-09-14 01:31:41 +020038
39echo 'wait for first program to carry out the lock release'
Neels Hofmeyr417a03d2017-05-04 14:48:49 +020040while [ ! -f "$f1.done" ]; do
41 sleep .1
42done
Neels Hofmeyr936a81e2017-09-14 01:31:41 +020043
44echo 'now expecting second program to lock'
Neels Hofmeyra6278b72017-05-10 13:46:11 +020045echo "waited, locked by: '$(cat "$dir/lock_test")'"
Neels Hofmeyr936a81e2017-09-14 01:31:41 +020046
47echo 'release the second program also'
Neels Hofmeyr417a03d2017-05-04 14:48:49 +020048rm "$f2"
49while [ ! -f "$f2.done" ]; do
50 sleep .1
51done
Neels Hofmeyr936a81e2017-09-14 01:31:41 +020052
53echo 'expecting the lock to be gone'
Neels Hofmeyra6278b72017-05-10 13:46:11 +020054echo "waited more, locked by: '$(cat "$dir/lock_test")'"
Neels Hofmeyr417a03d2017-05-04 14:48:49 +020055rm -rf "$dir"