[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

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-count

Potentially 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
> +fi

Slows 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

Attachment: signature.asc
Description: OpenPGP digital signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]