Eric Blake
2019-Sep-19 16:12 UTC
Re: [Libguestfs] [PATCH nbdkit v3 3/3] retry: Add a test of this filter.
On 9/19/19 10:26 AM, Richard W.M. Jones wrote:> We use a custom sh plugin to test retries are working. > --- > tests/Makefile.am | 8 +++ > tests/test-retry-reopen-fail.sh | 108 ++++++++++++++++++++++++++++++++ > tests/test-retry.sh | 97 ++++++++++++++++++++++++++++ > 3 files changed, 213 insertions(+) >> +++ b/tests/test-retry-reopen-fail.sh> + > +# Create a custom plugin which will test retrying. > +nbdkit -v -U - --filter=retry \ > + sh - \ > + --run 'qemu-img convert $nbd retry-reopen-fail.img' <<'EOF' > +case "$1" in > + open) > + # Count how many times the connection is (re-)opened. > + i=`cat retry-reopen-fail-open-count`$() is nicer than ``, but even better is just: read i retry-reopen-fail-open-count> + ((i++)) > + echo $i > retry-reopen-fail-open-countPotentially racy if more than one thread tries to do this - but sh plugins don't default to parallel and you aren't requesting parallel mode, so we are safe due to serialization. But maybe worth a comment?> + if [ $i -eq 2 ]; then > + echo "EIO open failed" >&2 > + exit 1 > + fi > + ;; > + pread) > + # Fail 3 times then succeed, and count how long it takes. > + i=`cat retry-reopen-fail-count`same thing about using 'read'> + > +# In this test we should see 4 failures: > +# pread FAILS > +# retry and wait 2 seconds > +# open FAILS > +# retry and wait 4 seconds > +# open succeeds > +# pread FAILS > +# retry and wait 8 seconds > +# pread FAILS > +# retry and wait 16 seconds > +# pread succeeds > + > +# The minimum time for the test should be 2+4+8+16 = 30 seconds. > +start_t=`stat -c '%Z' retry-reopen-fail-start` > +end_t=`date +'%s'` > +if [ $((end_t - start_t)) -lt 30 ]; then > + echo "$0: test ran too quickly" > + exit 1 > +fiSlows down 'make check'; is there any way we can scale it to be slightly faster, such as using a smaller retry interval than just 1 second as our starting point?> + > +# Check the handle was opened 5 times. > +retry_open_count=`cat retry-reopen-fail-open-count`Another potential 'read' spot.> +if [ $retry_open_count -ne 5 ]; then > + echo "$0: retry-reopen-fail-open-count ($retry_open_count) != 5" > + exit 1 > +fi > diff --git a/tests/test-retry.sh b/tests/test-retry.sh > new file mode 100755 > index 0000000..47d6e23 > --- /dev/null > +++ b/tests/test-retry.sh> +touch retry-start > + > +# Create a custom plugin which will test retrying. > +nbdkit -v -U - --filter=retry \ > + sh - \ > + --run 'qemu-img convert $nbd retry.img' <<'EOF' > +case "$1" in > + open) > + # Count how many times the connection is (re-)opened. > + i=`cat retry-open-count`and more in this file> + > +# The minimum time for the test should be 2+4+8 = 14 seconds. > +start_t=`stat -c '%Z' retry-start` > +end_t=`date +'%s'`I'm not sure how portable this will be to non-Linux, but we'll deal with that when someone complains. It may also be an issue if filesystem time is skewed in relation to system date. Bash includes $SECONDS which auto-increments at 1-second intervals, would testing that be more reliable than stat/date? -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Richard W.M. Jones
2019-Sep-19 17:04 UTC
Re: [Libguestfs] [PATCH nbdkit v3 3/3] retry: Add a test of this filter.
On Thu, Sep 19, 2019 at 11:12:23AM -0500, Eric Blake wrote:> > + open) > > + # Count how many times the connection is (re-)opened. > > + i=`cat retry-reopen-fail-open-count` > > $() is nicer than ``, but even better is just: > > read i retry-reopen-fail-open-countDid you mean: read i < retry-reopen-fail-open-count Unfortunately it fails when the file does not exist. (We could pre-create the files though). Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Eric Blake
2019-Sep-20 11:36 UTC
Re: [Libguestfs] [PATCH nbdkit v3 3/3] retry: Add a test of this filter.
On 9/19/19 12:04 PM, Richard W.M. Jones wrote:> On Thu, Sep 19, 2019 at 11:12:23AM -0500, Eric Blake wrote: >>> + open) >>> + # Count how many times the connection is (re-)opened. >>> + i=`cat retry-reopen-fail-open-count` >> >> $() is nicer than ``, but even better is just: >> >> read i retry-reopen-fail-open-count > > Did you mean: > > read i < retry-reopen-fail-open-countYes. Thanks for fixing my typo.> > Unfortunately it fails when the file does not exist. (We could > pre-create the files though).Yes, or even pre-populate it to contain '0' instead of being empty, if that makes it easier to track what it is doing. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Maybe Matching Threads
- Re: [PATCH nbdkit v3 3/3] retry: Add a test of this filter.
- sscanf/stroul (was: Re: [PATCH nbdkit v3 2/3] Add new retry filter.)
- [PATCH nbdkit v3 3/3] retry: Add a test of this filter.
- Re: [PATCH nbdkit v3 2/3] Add new retry filter.
- [PATCH nbdkit v3 2/3] Add new retry filter.