]> ruderich.org/simon Gitweb - tlsproxy/tlsproxy.git/commitdiff
tests: Wait until tlsproxy and gnutls-serv are ready.
authorSimon Ruderich <simon@ruderich.org>
Sun, 28 Jul 2013 12:18:08 +0000 (14:18 +0200)
committerSimon Ruderich <simon@ruderich.org>
Sun, 28 Jul 2013 12:18:08 +0000 (14:18 +0200)
Prevent failing tests on slower machines where sleep 1 is not enough.

tests/common.sh
tests/tests-normal.sh
tests/tests-passthrough.sh

index 1ca15837a47bdc5864db80e59f7de479f437a41c..d2b3459cee64123b75e81d65f3b80123c50e6aff 100644 (file)
@@ -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'
index 3b50f711119d0e95309cfd1dacba9a5dc271d9c3..5967c44ba1ff6485d8ccf2dff9f3e3cff2fa1ba7 100755 (executable)
@@ -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
 
 
index 4b4e3b252262132a21e426d3cf53fb6f8fbad062..55846489e52c9f52bf827301615b7270b2944403 100755 (executable)
@@ -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