tests/test-captive.sh: Try to make this test more stable on slower machines.
commit376cda7c1ede6f03f8e922e7eae8f8b60cdf8e79
authorRichard W.M. Jones <rjones@redhat.com>
Thu, 14 Nov 2019 11:11:22 +0000 (14 11:11 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Thu, 14 Nov 2019 11:11:22 +0000 (14 11:11 +0000)
tree2ae765c2dcb7fb36735aecb77bbf5916254fa1ae
parent180f88659ebe77ce7a7db59440d55fde19dbdcec
tests/test-captive.sh: Try to make this test more stable on slower machines.

This test relies on sending a signal to nbdkit which causes nbdkit to
exit before the captive subprocess.  On slow machines (especially
armv7 and s390x in Fedora Koji) it appears that the captive subprocess
can still exit before nbdkit receives the signal, resulting in an
incorrect exit status and test failure.

There's not a lot we can do here except to increase the sleep.
Alternatives might be to try to inspect the status of the nbdkit
process to see if it has become a zombie yet, but that would be hard
to make portable.

Typical failure on armv7:

FAIL: test-captive.sh
=====================
+ fail=0
++ mktemp -u
+ sock=/tmp/tmp.bHGd8vKHxI
+ files='/tmp/tmp.bHGd8vKHxI captive.out captive.pid'
+ rm -f /tmp/tmp.bHGd8vKHxI captive.out captive.pid
+ cleanup_fn rm -f /tmp/tmp.bHGd8vKHxI captive.out captive.pid
+ _cleanup_hook[${#_cleanup_hook[@]}]='rm -f /tmp/tmp.bHGd8vKHxI captive.out captive.pid'
+ nbdkit -U /tmp/tmp.bHGd8vKHxI example1 --run '
    echo nbd=$nbd; echo port=$port; echo socket=$unixsocket
  '
++ cat captive.out
+ '[' 'nbd=nbd:unix:/tmp/tmp.bHGd8vKHxI
port=
socket=/tmp/tmp.bHGd8vKHxI' '!=' 'nbd=nbd:unix:/tmp/tmp.bHGd8vKHxI
port=
socket=/tmp/tmp.bHGd8vKHxI' ']'
+ status=0
+ nbdkit -U - example1 --run 'exit 2'
+ status=2
+ test 2 '!=' 2
+ test -s captive.out
+ status=0
+ nbdkit -U - -P captive.pid example1 --run '
for i in {1..60}; do
    if test -s captive.pid; then break; fi
    sleep 1
done
if ! test -s captive.pid; then
    echo "$0: no pidfile yet"
    exit 10
fi
kill -s ABRT $(cat captive.pid) || exit 10
sleep 5
'
++ kill -l ABRT
+ test 0 '!=' 134
+ echo './test-captive.sh: unexpected exit status 0'
./test-captive.sh: unexpected exit status 0
+ fail=1
+ test -s captive.out
+ exit 1
+ _run_cleanup_hooks
+ status=1
+ set +e
+ trap '' INT QUIT TERM EXIT ERR
+ echo ./test-captive.sh: run cleanup hooks: exit code 1
./test-captive.sh: run cleanup hooks: exit code 1
+ (( i = 0 ))
+ (( i < 1 ))
+ rm -f /tmp/tmp.bHGd8vKHxI captive.out captive.pid
+ (( ++i  ))
+ (( i < 1 ))
+ exit 1
FAIL test-captive.sh (exit status: 1)

Typical failure on s390x:

FAIL: test-captive.sh
=====================
+ fail=0
++ mktemp -u
+ sock=/tmp/tmp.vTRXPPqeJR
+ files='/tmp/tmp.vTRXPPqeJR captive.out captive.pid'
+ rm -f /tmp/tmp.vTRXPPqeJR captive.out captive.pid
+ cleanup_fn rm -f /tmp/tmp.vTRXPPqeJR captive.out captive.pid
+ _cleanup_hook[${#_cleanup_hook[@]}]='rm -f /tmp/tmp.vTRXPPqeJR captive.out captive.pid'
+ nbdkit -U /tmp/tmp.vTRXPPqeJR example1 --run '
    echo nbd=$nbd; echo port=$port; echo socket=$unixsocket
  '
++ cat captive.out
+ '[' 'nbd=nbd:unix:/tmp/tmp.vTRXPPqeJR
port=
socket=/tmp/tmp.vTRXPPqeJR' '!=' 'nbd=nbd:unix:/tmp/tmp.vTRXPPqeJR
port=
socket=/tmp/tmp.vTRXPPqeJR' ']'
+ status=0
+ nbdkit -U - example1 --run 'exit 2'
+ status=2
+ test 2 '!=' 2
+ test -s captive.out
+ status=0
+ nbdkit -U - -P captive.pid example1 --run '
for i in {1..60}; do
    if test -s captive.pid; then break; fi
    sleep 1
done
if ! test -s captive.pid; then
    echo "$0: no pidfile yet"
    exit 10
fi
kill -s ABRT $(cat captive.pid) || exit 10
sleep 5
'
++ kill -l ABRT
+ test 0 '!=' 134
+ echo './test-captive.sh: unexpected exit status 0'
./test-captive.sh: unexpected exit status 0
+ fail=1
+ test -s captive.out
+ exit 1
+ _run_cleanup_hooks
+ status=1
+ set +e
+ trap '' INT QUIT TERM EXIT ERR
+ echo ./test-captive.sh: run cleanup hooks: exit code 1
./test-captive.sh: run cleanup hooks: exit code 1
+ (( i = 0 ))
+ (( i < 1 ))
+ rm -f /tmp/tmp.vTRXPPqeJR captive.out captive.pid
+ (( ++i  ))
+ (( i < 1 ))
+ exit 1
FAIL test-captive.sh (exit status: 1)
tests/test-captive.sh