ts_init "$*"
ts_check_test_command "$TS_CMD_FLOCK"
+ts_check_prog "ps"
function do_lock {
# general lock
GEN_OUTPUT="$TS_OUTPUT"
START=$(date '+%s')
+# running flock in background is not the best usage example
$TS_CMD_FLOCK --shared $TS_OUTDIR/lockfile \
bash -c 'echo "Locking"; sleep 3; echo "Unlocking"' \
> $GEN_OUTPUT 2>&1 &
+pid=$!
+# check for running background process
+if [ "$pid" -le "0" ] || ! kill -s 0 "$pid" &>/dev/null; then
+ ts_die "unable to run flock"
+fi
+# the lock should be established when flock has a child
+timeout 1s bash -c "while [ \$(ps --ppid $pid |wc -l) -lt 2 ]; do sleep 0.1 ;done" \
+ || ts_die "timeout waiting for flock child"
ts_init_subtest "non-block"
do_lock "--nonblock --conflict-exit-code 123" 123 "You will never see this!"