pty-deadlock.test: use background write, not non-blocking reads

Non-blocking reads turn out not to work so well on Cygwin
which has an older version of bash.
This commit is contained in:
John Hood
2016-01-11 06:15:24 -05:00
parent e61b3bd014
commit e0f0905778
+17 -13
View File
@@ -31,6 +31,7 @@ tmux_commands()
{ {
# An interactive shell is waiting for us in the mosh session. # An interactive shell is waiting for us in the mosh session.
# Start test... # Start test...
sleep 2
printf "send-keys 0x0d\n" printf "send-keys 0x0d\n"
sleep 1 sleep 1
# Stop output... # Stop output...
@@ -41,9 +42,9 @@ tmux_commands()
sleep 2 sleep 2
# And stop the test script, so it produces its exit messge. # And stop the test script, so it produces its exit messge.
printf "send-keys 0x0d\n" printf "send-keys 0x0d\n"
# need to sleep extra long here, to let child commands complete, # need to sleep extra long here, to let child commands complete
# and not have tmux exit prematurely # and buffers drain, and not have tmux exit prematurely
sleep 5 sleep 10
} }
tmux_stdin() tmux_stdin()
@@ -56,18 +57,21 @@ baseline()
{ {
# Make a lot of noise on stdout to keep mosh busy, and exit # Make a lot of noise on stdout to keep mosh busy, and exit
# with a distinctive message when we get a CR. Exit after 10s in any case. # with a distinctive message when we get a CR. Exit after 10s in any case.
trap "exit 1" TERM read x
(sleep 10; kill $$) & while true; do
printf 'a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz\n'
done &
printpid=$!
(sleep 30; kill $$ $printpid) &
killpid=$! killpid=$!
read x read x
# very, very old school way to get non-blocking reads in shell kill $printpid
tty=$(stty -g) # Try and make sure the printer stops writing before the following printf
trap "stty $tty" EXIT sleep 1
stty -icanon min 0 time 0 printf "\n=== normal exit ===\n"
while ! read x; do # Let tty queues drain, so the exit message gets to mosh-client
printf 'a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz\n' # before we exit
done sleep 4
printf "=== normal exit ===\n"
# Kill the killer and exit normally. # Kill the killer and exit normally.
kill $killpid kill $killpid
} }