tests/run.sh: Factor out a helper function
This factors out a function wait_until_success that runs some command until it succeeds (with a timeout) and uses this function in the two places where this was already done before. Note that this removes the "kill -0" trick for early exit again and instead will use the timeout in case awesome dies during startup. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
0688e8899e
commit
17e8827212
65
tests/run.sh
65
tests/run.sh
|
@ -75,27 +75,33 @@ tmp_files=$(mktemp -d)
|
||||||
awesome_log=$tmp_files/_awesome_test.log
|
awesome_log=$tmp_files/_awesome_test.log
|
||||||
echo "awesome_log: $awesome_log"
|
echo "awesome_log: $awesome_log"
|
||||||
|
|
||||||
|
wait_until_success() {
|
||||||
|
max_wait=60
|
||||||
|
while true; do
|
||||||
|
set +e
|
||||||
|
eval reply="\$($2)"
|
||||||
|
ret=$?
|
||||||
|
set -e
|
||||||
|
if [ $ret = 0 ]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
max_wait=$(expr $max_wait - 1 || true)
|
||||||
|
if [ "$max_wait" -lt 0 ]; then
|
||||||
|
echo "Error: failed to $1!"
|
||||||
|
echo "Last reply: $reply."
|
||||||
|
if [ -f "$awesome_log" ]; then
|
||||||
|
echo "Log:"
|
||||||
|
cat "$awesome_log"
|
||||||
|
fi
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
sleep 0.05
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# Wait for DISPLAY to be available, and setup xrdb,
|
# Wait for DISPLAY to be available, and setup xrdb,
|
||||||
# for awesome's xresources backend / queries.
|
# for awesome's xresources backend / queries.
|
||||||
max_wait=60
|
wait_until_success "setup xrdb" "echo 'Xft.dpi: 96' | DISPLAY='$D' xrdb 2>&1"
|
||||||
while true; do
|
|
||||||
set +e
|
|
||||||
reply="$(echo "Xft.dpi: 96" | DISPLAY="$D" xrdb 2>&1)"
|
|
||||||
ret=$?
|
|
||||||
set -e
|
|
||||||
if [ $ret = 0 ]; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
max_wait=$(expr $max_wait - 1)
|
|
||||||
if [ "$max_wait" -lt 0 ]; then
|
|
||||||
echo "Error: failed to setup xrdb!"
|
|
||||||
echo "Last reply: $reply."
|
|
||||||
echo "Log:"
|
|
||||||
cat "$awesome_log"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
sleep 0.05
|
|
||||||
done
|
|
||||||
|
|
||||||
# Use a separate D-Bus session; sets $DBUS_SESSION_BUS_PID.
|
# Use a separate D-Bus session; sets $DBUS_SESSION_BUS_PID.
|
||||||
eval $(DISPLAY="$D" dbus-launch --sh-syntax --exit-with-session)
|
eval $(DISPLAY="$D" dbus-launch --sh-syntax --exit-with-session)
|
||||||
|
@ -120,26 +126,7 @@ start_awesome() {
|
||||||
cd - >/dev/null
|
cd - >/dev/null
|
||||||
|
|
||||||
# Wait until the interface for awesome-client is ready (D-Bus interface).
|
# Wait until the interface for awesome-client is ready (D-Bus interface).
|
||||||
client_reply=
|
wait_until_success "wait for awesome startup via awesome-client" "echo 'return 1' | DISPLAY=$D '$AWESOME_CLIENT' 2>&1"
|
||||||
max_wait=50
|
|
||||||
while true; do
|
|
||||||
set +e
|
|
||||||
client_reply=$(echo 'return 1' | DISPLAY=$D "$AWESOME_CLIENT" 2>&1)
|
|
||||||
ret=$?
|
|
||||||
set -e
|
|
||||||
if [ $ret = 0 ]; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
max_wait=$(expr $max_wait - 1 || true)
|
|
||||||
if [ "$max_wait" -lt 0 ] || ! kill -0 $awesome_pid ; then
|
|
||||||
echo "Error: did not receive a successful reply via awesome-client!"
|
|
||||||
echo "Last reply: $client_reply."
|
|
||||||
echo "Log:"
|
|
||||||
cat "$awesome_log"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
sleep 0.1
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Count errors.
|
# Count errors.
|
||||||
|
|
Loading…
Reference in New Issue