]> ruderich.org/simon Gitweb - tlsproxy/tlsproxy.git/blobdiff - tests/common.sh
tests: Wait until tlsproxy and gnutls-serv are ready.
[tlsproxy/tlsproxy.git] / tests / common.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'