mosh-server: Support timeouts on lost connectivity to network client.
Closes #690.
This commit is contained in:
@@ -12,9 +12,11 @@ displaytests = \
|
||||
emulation-80th-column.test \
|
||||
emulation-back-tab.test \
|
||||
emulation-multiline-scroll.test \
|
||||
window-resize.test \
|
||||
server-network-timeout.test \
|
||||
server-signal-timeout.test \
|
||||
unicode-combine-fallback-assert.test \
|
||||
unicode-later-combining.test
|
||||
unicode-later-combining.test \
|
||||
window-resize.test
|
||||
|
||||
check_PROGRAMS = ocb-aes encrypt-decrypt base64
|
||||
TESTS = ocb-aes encrypt-decrypt base64 $(displaytests)
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
# then captures screen with `tmux capture-pane`. Captures exitstatus
|
||||
# of both and returns appropriate errors.
|
||||
#
|
||||
export MOSH_SERVER_PID=$PPID
|
||||
|
||||
if [ $# -lt 2 ]; then
|
||||
printf "not enough args\n" >&2
|
||||
exit 99
|
||||
@@ -12,6 +14,7 @@ fi
|
||||
testname=$1
|
||||
shift
|
||||
rm -f $testname.capture $testname.exitstatus
|
||||
trap ":" TERM HUP QUIT # If the session closes on us, let the test we're running drive.
|
||||
trap 'rv=$?; echo $rv > $testname.exitstatus; exit $rv' EXIT
|
||||
# check for tmux
|
||||
if [ -z "$TMUX_PANE" ]; then
|
||||
|
||||
Executable
+114
@@ -0,0 +1,114 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# This test checks for operation of the MOSH_SERVER_NETWORK_TIMEOUT variable.
|
||||
# It does this by
|
||||
# * setting the variable
|
||||
# * killing the client (and its network traffic)
|
||||
# * waiting server-side, for the server to die
|
||||
# If it is killed, the test is successful.
|
||||
# If it survives that long and the server is still around, the test fails.
|
||||
# The client waits a bit longer than the server so that status can be collected
|
||||
# properly.
|
||||
#
|
||||
|
||||
TIMEOUT=10
|
||||
|
||||
fail()
|
||||
{
|
||||
printf "$@" 2>&1
|
||||
exit 99
|
||||
}
|
||||
|
||||
|
||||
|
||||
PATH=$PATH:.:$srcdir
|
||||
# Top-level wrapper.
|
||||
if [ $# -eq 0 ]; then
|
||||
e2e-test $0 client baseline
|
||||
exit
|
||||
fi
|
||||
|
||||
# OK, we have arguments, we're one of the test hooks.
|
||||
|
||||
client()
|
||||
{
|
||||
case "$myname" in
|
||||
server-network-timeout)
|
||||
export MOSH_SERVER_NETWORK_TMOUT=$TIMEOUT;;
|
||||
server-signal-timeout)
|
||||
export MOSH_SERVER_SIGNAL_TMOUT=$TIMEOUT;;
|
||||
*)
|
||||
fail "unexpected test name %s\n" "$myname"
|
||||
esac
|
||||
shift
|
||||
eval "$@"
|
||||
# The client may be murdered. We need to expect that...
|
||||
retval=$?
|
||||
case $retval in
|
||||
0|1)
|
||||
fail "mosh-client had a normal exit\n";; # test condition failed
|
||||
137)
|
||||
# Aha, signal 9. Wait.
|
||||
sleep $(( $TIMEOUT + 12 ))
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
fail "unknown client wrapper failure, retval=%d\n" $retval
|
||||
;;
|
||||
esac
|
||||
fail "client wrapper shouldnt get here\n"
|
||||
}
|
||||
baseline()
|
||||
{
|
||||
# check for our wonderful variable
|
||||
if [ -z "$MOSH_SERVER_NETWORK_TMOUT" -a -z "$MOSH_SERVER_SIGNAL_TMOUT" ]; then
|
||||
env
|
||||
fail "Variable unset\n"
|
||||
fi
|
||||
# check for our client
|
||||
if [ -z "$MOSH_CLIENT_PID" ]; then
|
||||
env
|
||||
fail "Client pid unavailable\n"
|
||||
fi
|
||||
if ! kill -0 $MOSH_CLIENT_PID; then
|
||||
fail "mosh client is unexpectedly missing\n"
|
||||
fi
|
||||
# Set up for good return and cleanup on being killed
|
||||
trap "echo got killed >&2; sleep 1; exit 0" SIGHUP SIGTERM
|
||||
sleep 1
|
||||
|
||||
# Kill the client, to stop network traffic.
|
||||
kill -KILL $MOSH_CLIENT_PID
|
||||
case "$myname" in
|
||||
server-network-timeout)
|
||||
# Just wait. This is the hardest part.
|
||||
sleep $(( $TIMEOUT + 7 ))
|
||||
;;
|
||||
server-signal-timeout)
|
||||
# Wait for the timeout to expire.
|
||||
sleep $(( $TIMEOUT + 2 ))
|
||||
# Tell the server to go away.
|
||||
kill -USR1 $MOSH_SERVER_PID
|
||||
sleep 5
|
||||
;;
|
||||
*)
|
||||
fail "unexpected test name %s\n" "$myname"
|
||||
esac
|
||||
# If we're still alive and the server is too, the test failed.
|
||||
# XXX the server is getting killed and we're getting here anyway.
|
||||
# Exit with error only if server is still around.
|
||||
! kill -0 $MOSH_SERVER_PID
|
||||
exit
|
||||
}
|
||||
|
||||
myname="$(basename $0 .test)"
|
||||
|
||||
case $1 in
|
||||
baseline|variant)
|
||||
baseline;;
|
||||
client)
|
||||
client "$@";;
|
||||
*)
|
||||
fail "unknown test argument %s\n" $1;;
|
||||
esac
|
||||
+1
@@ -0,0 +1 @@
|
||||
server-network-timeout.test
|
||||
Reference in New Issue
Block a user