[Libguestfs] [nbdkit PATCH] tests: Test for faster shutdown

Eric Blake eblake at redhat.com
Tue Aug 6 15:46:30 UTC 2019


The test relies on the timeout program.  Also, since the
nbdkit_nanosleep code relies on the Linux extension POLLRDHUP to
detect early client closure, we may have to relax that part of the
test when porting to platforms that lack ppoll/POLLRDHUP.  (That is,
while we should still be able to let a signal to the server shut down
nbdkit quickly, it's harder to let a client close()ing its end cause
nbdkit to shut down a single connection quickly when limited to a poll
that can't identify EOF as a way to break a poll).

Signed-off-by: Eric Blake <eblake at redhat.com>
---

I'm pushing this along with the nbdkit_nanosleep patches, now that I'm
reliably getting the test to fail in isolation and to pass with the
sleep patches applied.  However, I suspect that we will definitely need
to fix things for other platforms, and/or skip this test if we can't
easily make other platforms match what Linux can do with POLLRDHUP.

 tests/Makefile.am      |  4 ++-
 tests/test-shutdown.sh | 76 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+), 1 deletion(-)
 create mode 100755 tests/test-shutdown.sh

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3d78e7a2..bc308c5d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -110,6 +110,7 @@ EXTRA_DIST = \
 	test-rate-dynamic.sh \
 	test.rb \
 	test-readahead-copy.sh \
+	test-shutdown.sh \
 	test-ssh.sh \
 	test.tcl \
 	test-shebang-perl.sh \
@@ -955,7 +956,8 @@ if HAVE_GUESTFISH
 TESTS += test-cow.sh
 endif HAVE_GUESTFISH

-# delay filter test.
+# delay filter tests.
+TESTS += test-shutdown.sh
 LIBGUESTFS_TESTS += test-delay

 test_delay_SOURCES = test-delay.c test.h
diff --git a/tests/test-shutdown.sh b/tests/test-shutdown.sh
new file mode 100755
index 00000000..0ac9c1eb
--- /dev/null
+++ b/tests/test-shutdown.sh
@@ -0,0 +1,76 @@
+#!/usr/bin/env bash
+# nbdkit
+# Copyright (C) 2019 Red Hat Inc.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# * Neither the name of Red Hat nor the names of its contributors may be
+# used to endorse or promote products derived from this software without
+# specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
+source ./functions.sh
+set -x
+
+requires qemu-io --version
+requires timeout --version
+
+sock=`mktemp -u`
+files="shutdown.pid $sock"
+cleanup_fn rm -f $files
+fail=0
+
+# Create a server that delays reads and forces only one connection at a time.
+# This tests that the delay filter's use of nbdkit_nanosleep is able to
+# react to both connection death and server shutdown without finishing
+# the entire delay duration.
+start_nbdkit -P shutdown.pid -U $sock --filter=noparallel --filter=delay \
+    null 1M serialize=connections rdelay=10
+
+# Early client death should not stall connection of second client.
+trap '' ERR
+timeout 1s qemu-io -f raw "nbd+unix:///?socket=$sock" -c 'r 0 512' </dev/null
+test $? = 124 || {
+    echo "Unexpected status; qemu-io should have been killed for timing out"
+    fail=1
+}
+timeout 1s qemu-io -f raw "nbd+unix:///?socket=$sock" -c 'quit' </dev/null
+test $? = 0 || {
+    echo "Unexpected status; nbdkit was not responsive to allow second qemu-io"
+    fail=1
+}
+
+# The server's response to shutdown signals should not stall on delays
+qemu-io -f raw "nbd+unix:///?socket=$sock" -c 'r 0 512' </dev/null &
+pid=$!
+sleep 1
+kill -s INT "$(cat "$pidfile")"
+sleep 1
+kill -s 0 "$(cat "$pidfile")" && {
+    echo "Unexpected status; nbdkit didn't react fast enough to signal"
+    fail=1
+}
+wait $pid
+
+exit $fail
-- 
2.20.1




More information about the Libguestfs mailing list