* [PATCH] tests: wait for flock background process
@ 2016-11-02 14:31 Ruediger Meier
2016-11-02 15:51 ` Karel Zak
0 siblings, 1 reply; 6+ messages in thread
From: Ruediger Meier @ 2016-11-02 14:31 UTC (permalink / raw)
To: util-linux
From: Ruediger Meier <ruediger.meier@ga-group.nl>
Maybe we should add a --daemonize option to flock to cover
this use case.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
---
tests/ts/misc/flock | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/tests/ts/misc/flock b/tests/ts/misc/flock
index b2fc772..39e88de 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!"
--
1.8.5.6
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] tests: wait for flock background process
2016-11-02 14:31 [PATCH] tests: wait for flock background process Ruediger Meier
@ 2016-11-02 15:51 ` Karel Zak
2016-11-02 22:11 ` Bernhard Voelker
0 siblings, 1 reply; 6+ messages in thread
From: Karel Zak @ 2016-11-02 15:51 UTC (permalink / raw)
To: Ruediger Meier; +Cc: util-linux
On Wed, Nov 02, 2016 at 03:31:55PM +0100, Ruediger Meier wrote:
> From: Ruediger Meier <ruediger.meier@ga-group.nl>
>
> Maybe we should add a --daemonize option to flock to cover
> this use case.
I have doubts it will be usable for anything else than for our tests :-)
> tests/ts/misc/flock | 10 ++++++++++
> 1 file changed, 10 insertions(+)
Applied, thanks!
> +# 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" \
is "0.1" portable? :-)
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] tests: wait for flock background process
2016-11-02 15:51 ` Karel Zak
@ 2016-11-02 22:11 ` Bernhard Voelker
2016-11-02 23:08 ` Karel Zak
0 siblings, 1 reply; 6+ messages in thread
From: Bernhard Voelker @ 2016-11-02 22:11 UTC (permalink / raw)
To: Karel Zak, Ruediger Meier; +Cc: util-linux
On 11/02/2016 04:51 PM, Karel Zak wrote:
>> +timeout 1s bash -c "while [ \$(ps --ppid $pid |wc -l) -lt 2 ]; do sleep 0.1 ;done" \
>
> is "0.1" portable? :-)
if one has timeout from coreutils, then it's likely that she also has sleep
from there. Thus said, I'd rather worry about portability of using timeout
rather than the "0.1" (if sleep fails, then nobody will care anyway). ;-)
Have a nice day,
Berny
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] tests: wait for flock background process
2016-11-02 22:11 ` Bernhard Voelker
@ 2016-11-02 23:08 ` Karel Zak
2016-11-03 6:57 ` Ruediger Meier
0 siblings, 1 reply; 6+ messages in thread
From: Karel Zak @ 2016-11-02 23:08 UTC (permalink / raw)
To: Bernhard Voelker; +Cc: Ruediger Meier, util-linux
On Wed, Nov 02, 2016 at 11:11:42PM +0100, Bernhard Voelker wrote:
> On 11/02/2016 04:51 PM, Karel Zak wrote:
> >> +timeout 1s bash -c "while [ \$(ps --ppid $pid |wc -l) -lt 2 ]; do sleep 0.1 ;done" \
> >
> > is "0.1" portable? :-)
>
> if one has timeout from coreutils, then it's likely that she also has sleep
> from there. Thus said, I'd rather worry about portability of using timeout
> rather than the "0.1" (if sleep fails, then nobody will care anyway). ;-)
Good point... I have added check for "timeout".
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] tests: wait for flock background process
2016-11-02 23:08 ` Karel Zak
@ 2016-11-03 6:57 ` Ruediger Meier
2016-11-03 12:09 ` Pádraig Brady
0 siblings, 1 reply; 6+ messages in thread
From: Ruediger Meier @ 2016-11-03 6:57 UTC (permalink / raw)
To: Karel Zak; +Cc: Bernhard Voelker, util-linux
On Thursday 03 November 2016, Karel Zak wrote:
> On Wed, Nov 02, 2016 at 11:11:42PM +0100, Bernhard Voelker wrote:
> > On 11/02/2016 04:51 PM, Karel Zak wrote:
> > >> +timeout 1s bash -c "while [ \$(ps --ppid $pid |wc -l) -lt 2 ];
> > >> do sleep 0.1 ;done" \
> > >
> > > is "0.1" portable? :-)
> >
> > if one has timeout from coreutils, then it's likely that she also
> > has sleep from there. Thus said, I'd rather worry about
> > portability of using timeout rather than the "0.1" (if sleep fails,
> > then nobody will care anyway). ;-)
>
> Good point... I have added check for "timeout".
BTW we have already a lot more coreutils and other GNU dependencies in
our tests, inclusive timeout and sleep for floats.
AFAIR for v2.28 I had fixed all GNU deps for configure/make but for the
test-suite it was too painful. The OSX build on travis needs for the
tests at least GNU readlink, seq, truncate, find, xargs, tar and sed.
The Linux-only tests have even more coreutils deps.
To replace sleep for floats, we could check and use usleep(1) from
sysvinit. Or we could even add usleep to util-linux as we did with
other sysvinit commands.
cu,
Rudi
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] tests: wait for flock background process
2016-11-03 6:57 ` Ruediger Meier
@ 2016-11-03 12:09 ` Pádraig Brady
0 siblings, 0 replies; 6+ messages in thread
From: Pádraig Brady @ 2016-11-03 12:09 UTC (permalink / raw)
To: Ruediger Meier, Karel Zak; +Cc: Bernhard Voelker, util-linux
On 03/11/16 06:57, Ruediger Meier wrote:
> To replace sleep for floats, we could check and use usleep(1) from
> sysvinit. Or we could even add usleep to util-linux as we did with
> other sysvinit commands.
I previously suggested this technique to kernel folks,
who use it in linux kernel tests:
yield() { sleep .001 || usleep 1 || sleep 1; }
cheers,
Pádraig.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-11-03 12:09 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-02 14:31 [PATCH] tests: wait for flock background process Ruediger Meier
2016-11-02 15:51 ` Karel Zak
2016-11-02 22:11 ` Bernhard Voelker
2016-11-02 23:08 ` Karel Zak
2016-11-03 6:57 ` Ruediger Meier
2016-11-03 12:09 ` Pádraig Brady
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox