Prevent failing tests on slower machines where sleep 1 is not enough.
./client ./proxy-ca.pem "$@" > tmp 2>&1
}
+wait_for_ports() {
+ while :; do
+ sleep 1
+
+ # Check if each given port can be reached.
+ ready=1
+ for port in "$@"; do
+ printf 'invalid request\r\n\r\n' \
+ | nc localhost "$port" >/dev/null 2>&1 \
+ || ready=
+ done
+
+ if test -n "$ready"; then
+ break
+ fi
+
+ echo "waiting for ports $* ..."
+ done
+}
+
test_proxy_failure() {
grep 'proxy failure' tmp >/dev/null \
|| abort 'test_proxy_failure'
tlsproxy 4711
server --x509certfile "$srcdir/server.pem" \
--x509keyfile "$srcdir/server-key.pem"
-sleep 1
+wait_for_ports 4711 4712
echo invalid hostname
kill $pid_server || echo 'failed to kill gnutls-serv'
server --x509certfile "$srcdir/server-bad.pem" \
--x509keyfile "$srcdir/server-key.pem"
-sleep 1
+wait_for_ports 4712
rm -f certificate-localhost-proxy.pem certificate-localhost-server.pem
tlsproxy -u 4711
server --x509certfile "$srcdir/server.pem" \
--x509keyfile "$srcdir/server-key.pem"
-sleep 1
+wait_for_ports 4711 4712
echo invalid hostname
kill $pid_server || echo 'failed to kill gnutls-serv'
server --x509certfile "$srcdir/server-bad.pem" \
--x509keyfile "$srcdir/server-key.pem"
-sleep 1
+wait_for_ports 4712
rm -f certificate-localhost-proxy.pem certificate-localhost-server.pem