From 66293e8caa6d5347f86692ba0770890a7634e7ce Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 19 May 2017 11:25:59 +0000 Subject: [PATCH] Factor out 'wait_for_x' loop to reduce duplication --- test/840_weave_kube_3_test.sh | 14 +++----------- test/config.sh | 36 +++++++++++++++++++---------------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/test/840_weave_kube_3_test.sh b/test/840_weave_kube_3_test.sh index ac1a9c00..387c8fb1 100755 --- a/test/840_weave_kube_3_test.sh +++ b/test/840_weave_kube_3_test.sh @@ -44,19 +44,11 @@ sed -e "s%imagePullPolicy: Always%imagePullPolicy: Never$COVERAGE_ARGS%" "$(dirn sleep 5 -wait_for_connections() { - for i in $(seq 1 45); do - if run_on $HOST1 "curl -sS http://127.0.0.1:6784/status | grep \"$SUCCESS\"" ; then - return - fi - echo "Waiting for connections" - sleep 1 - done - echo "Timed out waiting for connections to establish" >&2 - exit 1 +check_connections() { + run_on $HOST1 "curl -sS http://127.0.0.1:6784/status | grep \"$SUCCESS\"" } -assert_raises wait_for_connections +assert_raises 'wait_for_x check_connections "connections to establish"' # Check we can ping between the Weave bridg IPs on each host HOST1EXPIP=$($SSH $HOST1 "weave expose" || true) diff --git a/test/config.sh b/test/config.sh index d25c9152..2174934e 100644 --- a/test/config.sh +++ b/test/config.sh @@ -218,18 +218,28 @@ proxy_start_container_with_dns() { proxy docker_on $host run "$@" -dt $DNS_IMAGE /bin/sh } -wait_for_proxy() { - for i in $(seq 1 120); do - echo "Waiting for proxy to start" - if proxy docker_on $1 info > /dev/null 2>&1 ; then +# Execute command $1 repeatedly until it returns true; description in $2, optional repeat limit in $3 +wait_for_x() { + reps=${3:-45} + for i in $(seq 1 $reps); do + echo "Waiting for $2" + if $1 ; then return fi sleep 1 done - echo "Timed out waiting for proxy to start" >&2 + echo "Timed out waiting for $2" >&2 exit 1 } +check_proxy() { + proxy docker_on $1 info >/dev/null 2>&1 +} + +wait_for_proxy() { + wait_for_x check_proxy "proxy to start" 120 +} + rm_containers() { host=$1 shift @@ -244,18 +254,12 @@ container_pid() { docker_on $1 inspect -f '{{.State.Pid}}' $2 } +check_attached() { + exec_on $1 $2 $CHECK_ETHWE_UP >/dev/null 2>&1 +} + wait_for_attached() { - host=$1 - container=$2 - for i in $(seq 1 10); do - echo "Waiting for $container on $host to be attached" - if exec_on $host $container $CHECK_ETHWE_UP > /dev/null 2>&1 ; then - return - fi - sleep 1 - done - echo "Timed out waiting for $container on $host to be attached" >&2 - exit 1 + wait_for_x "check_attached $1 $2" "$2 on $1 to be attached" } # assert_dns_record [ ...]