From: Simon Ruderich Date: Sun, 28 Jul 2013 12:18:08 +0000 (+0200) Subject: tests: Wait until tlsproxy and gnutls-serv are ready. X-Git-Url: https://ruderich.org/simon/gitweb/?p=tlsproxy%2Ftlsproxy.git;a=commitdiff_plain;h=9fb20ff647d6d494d99184875d2c60586107d34c tests: Wait until tlsproxy and gnutls-serv are ready. Prevent failing tests on slower machines where sleep 1 is not enough. --- diff --git a/tests/common.sh b/tests/common.sh index 1ca1583..d2b3459 100644 --- a/tests/common.sh +++ b/tests/common.sh @@ -46,6 +46,26 @@ client() { ./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' diff --git a/tests/tests-normal.sh b/tests/tests-normal.sh index 3b50f71..5967c44 100755 --- a/tests/tests-normal.sh +++ b/tests/tests-normal.sh @@ -30,7 +30,7 @@ cleanup tlsproxy 4711 server --x509certfile "$srcdir/server.pem" \ --x509keyfile "$srcdir/server-key.pem" -sleep 1 +wait_for_ports 4711 4712 echo invalid hostname @@ -73,7 +73,7 @@ echo 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 diff --git a/tests/tests-passthrough.sh b/tests/tests-passthrough.sh index 4b4e3b2..5584648 100755 --- a/tests/tests-passthrough.sh +++ b/tests/tests-passthrough.sh @@ -30,7 +30,7 @@ cleanup tlsproxy -u 4711 server --x509certfile "$srcdir/server.pem" \ --x509keyfile "$srcdir/server-key.pem" -sleep 1 +wait_for_ports 4711 4712 echo invalid hostname @@ -75,7 +75,7 @@ echo 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