aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRuediger Meier <ruediger.meier@ga-group.nl>2016-11-02 15:31:55 +0100
committerKarel Zak <kzak@redhat.com>2016-11-02 16:47:45 +0100
commitca6d721a01e99c08db844705d391496f1d041750 (patch)
treef5a3fc2c2ebbb6ab63bcad339de3cbf4eaf33e2e
parente76e6747cbd9eb1facbdb6026481e680c256750b (diff)
downloadutil-linux-ca6d721a01e99c08db844705d391496f1d041750.tar.gz
tests: wait for flock background process
Maybe we should add a --daemonize option to flock to cover this use case. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
-rwxr-xr-xtests/ts/misc/flock10
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/ts/misc/flock b/tests/ts/misc/flock
index b2fc772427..39e88dedf9 100755
--- a/tests/ts/misc/flock
+++ b/tests/ts/misc/flock
@@ -19,6 +19,7 @@ TS_DESC="flock"
ts_init "$*"
ts_check_test_command "$TS_CMD_FLOCK"
+ts_check_prog "ps"
function do_lock {
@@ -42,10 +43,19 @@ 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!"