From 9fb20ff647d6d494d99184875d2c60586107d34c Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 28 Jul 2013 14:18:08 +0200 Subject: [PATCH] tests: Wait until tlsproxy and gnutls-serv are ready. Prevent failing tests on slower machines where sleep 1 is not enough. --- tests/common.sh | 20 ++++++++++++++++++++ tests/tests-normal.sh | 4 ++-- tests/tests-passthrough.sh | 4 ++-- 3 files changed, 24 insertions(+), 4 deletions(-) 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 -- 2.45.2