compat.sh: use wait_server_start

Port wait_server_start from ssl-opt.sh to compat.sh, instead of just
using "sleep 1". This solves the problem that on a heavily loaded
machine, sleep 1 is sometimes not enough (we had CI failures because
of this). This is also faster on a lightly-loaded machine (execution
time reduced from ~8min to ~6min on my machine).
This commit is contained in:
Gilles Peskine 2017-12-14 19:02:00 +01:00
parent 418b536028
commit 12c49c7f7c

View file

@ -866,6 +866,33 @@ has_mem_err() {
fi fi
} }
# Wait for process $2 to be listening on port $1
if type lsof >/dev/null 2>/dev/null; then
wait_server_start() {
START_TIME=$(date +%s)
if is_dtls "$MODE"; then
proto=UDP
else
proto=TCP
fi
while ! lsof -a -n -b -i "$proto:$1" -p "$2" >/dev/null 2>/dev/null; do
if [ $(( $(date +%s) - $START_TIME )) -gt $DOG_DELAY ]; then
echo "SERVERSTART TIMEOUT"
echo "SERVERSTART TIMEOUT" >> $SRV_OUT
break
fi
# Linux and *BSD support decimal arguments to sleep. On other
# OSes this may be a tight loop.
sleep 0.1 2>/dev/null || true
done
}
else
wait_server_start() {
sleep 1
}
fi
# start_server <name> # start_server <name>
# also saves name and command # also saves name and command
start_server() { start_server() {
@ -895,7 +922,7 @@ start_server() {
while :; do echo bla; sleep 1; done | $SERVER_CMD >> $SRV_OUT 2>&1 & while :; do echo bla; sleep 1; done | $SERVER_CMD >> $SRV_OUT 2>&1 &
PROCESS_ID=$! PROCESS_ID=$!
sleep 1 wait_server_start "$PORT" "$PROCESS_ID"
} }
# terminate the running server # terminate the running server