Copy the paradigm of test-parallel-file.sh to further test that the
nbd forwarder can handle out-of-order requests. Once again, the
delay values I chose requires at least 5 seconds to complete; I don't
know if it is worth trying to fine-tune it to run faster while still
being robust in the presence of a heavy load.
With multiple nbdkit processes active during the test, it gets hairy
to write a nested --run that properly quotes the arguments needed for
two automatic Unix socket names. So this test instead resorts to
running the file plugin using --exit-with-parent within a subshell.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
tests/Makefile.am | 1 +
tests/test-parallel-nbd.sh | 81 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 82 insertions(+)
create mode 100755 tests/test-parallel-nbd.sh
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3989c0f..ddd53d5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -153,6 +153,7 @@ file-data:
if HAVE_QEMU_IO
TESTS_ENVIRONMENT += QEMU_IO=$(QEMU_IO)
TESTS += test-parallel-file.sh
+TESTS += test-parallel-nbd.sh
endif HAVE_QEMU_IO
endif HAVE_PLUGINS
diff --git a/tests/test-parallel-nbd.sh b/tests/test-parallel-nbd.sh
new file mode 100755
index 0000000..233118b
--- /dev/null
+++ b/tests/test-parallel-nbd.sh
@@ -0,0 +1,81 @@
+#!/bin/bash -
+# nbdkit
+# Copyright (C) 2017 Red Hat Inc.
+# All rights reserved.
+#
+# 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.
+
+# Makefile sets $QEMU_IO and builds file-data, but it's also nice if the
+# script runs again standalone afterwards for diagnosing any failures
+test -f file-data || { echo "Missing file-data"; exit 77; }
+: ${QEMU_IO=qemu-io}
+
+# Sanity check that qemu-io can issue parallel requests
+$QEMU_IO -f raw -c "aio_read 0 1" -c "aio_write -P 2 1 1" -c
aio_flush \
+ file-data || { echo "'$QEMU_IO' can't drive parallel requests";
exit 77; }
+
+# We require --exit-with-parent to work
+( nbdkit --exit-with-parent --help ) >/dev/null 2>&1 ||
+ { echo "Missing --exit-with-parent support"; exit 77; }
+
+# Set up the file plugin to delay both reads and writes (for a good chance
+# that parallel requests are in flight), and with reads longer than writes
+# (to more easily detect if out-of-order completion happens). This test
+# may have spurious failures under heavy loads on the test machine, where
+# tuning the delays may help.
+
+trap 'rm -f test-parallel-nbd.out test-parallel-nbd.sock' 0 1 2 3 15
+(
+rm -f test-parallel-nbd.sock
+nbdkit --exit-with-parent -v -U test-parallel-nbd.sock \
+ file file=file-data rdelay=2 wdelay=1 &
+
+# With --threads=1, the read should complete first because it was issued first
+nbdkit -v -t 1 -U - nbd socket=test-parallel-nbd.sock --run '
+ $QEMU_IO -f raw -c "aio_read 0 1" -c "aio_write -P 2 1 1" -c
aio_flush $nbd
+' | tee test-parallel-nbd.out
+if test "$(grep '1/1' test-parallel-nbd.out)" != \
+"read 1/1 bytes at offset 0
+wrote 1/1 bytes at offset 1"; then
+ exit 1
+fi
+
+# With default --threads, the faster write should complete first
+nbdkit -v -U - nbd socket=test-parallel-nbd.sock --run '
+ $QEMU_IO -f raw -c "aio_read 0 1" -c "aio_write -P 2 1 1" -c
aio_flush $nbd
+' | tee test-parallel-nbd.out
+if test "$(grep '1/1' test-parallel-nbd.out)" != \
+"wrote 1/1 bytes at offset 1
+read 1/1 bytes at offset 0"; then
+ exit 1
+fi
+
+) || exit $?
+
+exit 0
--
2.13.6