diff --git a/integration/100_launch_test.sh b/integration/100_launch_test.sh index a51935a9f..3dd7ca853 100755 --- a/integration/100_launch_test.sh +++ b/integration/100_launch_test.sh @@ -7,10 +7,10 @@ start_suite "Launch scope and check it boots" weave_on $HOST1 launch scope_on $HOST1 launch -sleep 5 # give the probe a few seconds to build a report and send it to the app +wait_for_containers $HOST1 60 weave weaveproxy weavescope -has_container $HOST1 weave 1 -has_container $HOST1 weaveproxy 1 -has_container $HOST1 weavescope 1 +has_container $HOST1 weave +has_container $HOST1 weaveproxy +has_container $HOST1 weavescope scope_end_suite diff --git a/integration/105_launch_sans_weave_test.sh b/integration/105_launch_sans_weave_test.sh index 8c0c702ea..d3a66a562 100755 --- a/integration/105_launch_sans_weave_test.sh +++ b/integration/105_launch_sans_weave_test.sh @@ -6,10 +6,10 @@ start_suite "Launch scope (without weave installed) and check it boots" scope_on $HOST1 launch -sleep 5 # give the probe a few seconds to build a report and send it to the app +wait_for_containers $HOST1 60 weavescope has_container $HOST1 weave 0 has_container $HOST1 weaveproxy 0 -has_container $HOST1 weavescope 1 +has_container $HOST1 weavescope scope_end_suite diff --git a/integration/200_clustering_2_test.sh b/integration/200_clustering_2_test.sh index 64b3310fe..3982d11aa 100755 --- a/integration/200_clustering_2_test.sh +++ b/integration/200_clustering_2_test.sh @@ -19,8 +19,8 @@ check() { has_container $1 weave 2 has_container $1 weaveproxy 2 has_container $1 weavescope 2 - has_container $1 db1 1 - has_container $1 db2 1 + has_container $1 db1 + has_container $1 db2 } check $HOST1 diff --git a/integration/205_clustering_sans_weave_2_test.sh b/integration/205_clustering_sans_weave_2_test.sh index 0a929fece..abd498682 100755 --- a/integration/205_clustering_sans_weave_2_test.sh +++ b/integration/205_clustering_sans_weave_2_test.sh @@ -16,8 +16,8 @@ check() { has_container $1 weave 0 has_container $1 weaveproxy 0 has_container $1 weavescope 2 - has_container $1 db1 1 - has_container $1 db2 1 + has_container $1 db1 + has_container $1 db2 } check $HOST1 diff --git a/integration/300_internet_edge_test.sh b/integration/300_internet_edge_test.sh index 1b3a61a5d..cb56e038b 100755 --- a/integration/300_internet_edge_test.sh +++ b/integration/300_internet_edge_test.sh @@ -10,16 +10,17 @@ docker_on $HOST1 run -d -p 80:80 --name nginx nginx do_connections() { while true; do - curl -s http://$HOST1:80/ >/dev/null + curl -s http://$HOST1:80/ >/dev/null || true sleep 1 done } do_connections& -sleep 5 # give the probe a few seconds to build a report and send it to the app +wait_for_containers $HOST1 60 nginx "The Internet" -has_container $HOST1 nginx 1 -has_connection $HOST1 "The Internet" nginx +has_container $HOST1 nginx +has_container $HOST1 "The Internet" +has_connection $HOST1 "The Internet" nginx 60 kill %do_connections diff --git a/integration/310_container_to_container_edge_test.sh b/integration/310_container_to_container_edge_test.sh index b1585923e..87327e34e 100755 --- a/integration/310_container_to_container_edge_test.sh +++ b/integration/310_container_to_container_edge_test.sh @@ -9,10 +9,10 @@ scope_on $HOST1 launch weave_on $HOST1 run -d --name nginx nginx weave_on $HOST1 run -d --name client alpine /bin/sh -c "while true; do wget http://nginx.weave.local:80/ >/dev/null; sleep 1; done" -sleep 20 # give the probe a few seconds to build a report and send it to the app +wait_for_containers $HOST1 60 nginx client -has_container $HOST1 nginx 1 -has_container $HOST1 client 1 +has_container $HOST1 nginx +has_container $HOST1 client has_connection $HOST1 client nginx scope_end_suite diff --git a/integration/320_container_edge_cross_host_2_test.sh b/integration/320_container_edge_cross_host_2_test.sh index ba98276e1..67d1b4886 100755 --- a/integration/320_container_edge_cross_host_2_test.sh +++ b/integration/320_container_edge_cross_host_2_test.sh @@ -16,8 +16,8 @@ weave_on $HOST2 run -d --name client alpine /bin/sh -c "while true; do wget http sleep 30 # need to allow the scopes to poll dns, resolve the other app ids, and send them reports check() { - has_container $1 nginx 1 - has_container $1 client 1 + has_container $1 nginx + has_container $1 client has_connection $1 client nginx } diff --git a/integration/config.sh b/integration/config.sh index d41e06ef4..daf72dfbd 100644 --- a/integration/config.sh +++ b/integration/config.sh @@ -35,7 +35,7 @@ weave_on() { has_container() { local host=$1 local name=$2 - local count=$3 + local count=${3:-1} assert "curl -s http://$host:4040/api/topology/containers?system=show | jq -r '[.nodes[] | select(.label_major == \"$name\")] | length'" $count } @@ -57,7 +57,47 @@ has_connection() { local host="$1" local from="$2" local to="$3" + local timeout="${4:-10}" local from_id=$(container_id "$host" "$from") local to_id=$(container_id "$host" "$to") - assert "curl -s http://$host:4040/api/topology/containers?system=show | jq -r '.nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])'" true + + for i in $(seq $timeout); do + local containers="$(curl -s http://$host:4040/api/topology/containers?system=show)" + local edge=$(echo "$containers" | jq -r ".nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])") + if [ "$edge" = "true" ]; then + echo "Found edge $from -> $to after $i secs" + assert "curl -s http://$host:4040/api/topology/containers?system=show | jq -r '.nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])'" true + return + fi + sleep 1 + done + + echo "Failed to fing edge $from -> $to after $timeout secs" + assert "curl -s http://$host:4040/api/topology/containers?system=show | jq -r '.nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])'" true +} + +wait_for_containers() { + local host="$1" + local timeout="$2" + shift 2 + + for i in $(seq $timeout); do + local containers="$(curl -s http://$host:4040/api/topology/containers?system=show)" + local found=0 + for name in "$@"; do + local count=$(echo "$containers" | jq -r "[.nodes[] | select(.label_major == \"$name\")] | length") + if [ "$count" -ge 1 ]; then + found=$(( found + 1 )) + fi + done + + if [ "$found" -eq $# ]; then + echo "Found $found containers after $i secs" + return + fi + + sleep 1 + done + + echo "Failed to find containers $@ after $i secs" } diff --git a/integration/setup.sh b/integration/setup.sh index 2ef69b345..b16b475f6 100755 --- a/integration/setup.sh +++ b/integration/setup.sh @@ -6,22 +6,23 @@ set -e echo Copying scope images and scripts to hosts for HOST in $HOSTS; do - docker_on $HOST load -i ../scope.tar - upload_executable $HOST ../scope - upload_executable $HOST ../scope /usr/local/scope/bin/scope + docker_on $HOST load -i ../scope.tar + upload_executable $HOST ../scope + upload_executable $HOST ../scope /usr/local/scope/bin/scope done echo Installing weave for HOST in $HOSTS; do - run_on $HOST "sudo curl -sL git.io/weave -o /usr/local/bin/weave" - run_on $HOST "sudo chmod a+x /usr/local/bin/weave" + run_on $HOST "sudo curl -sL git.io/weave -o /usr/local/bin/weave" + run_on $HOST "sudo chmod a+x /usr/local/bin/weave" done echo Prefetching Images for HOST in $HOSTS; do - weave_on $HOST setup - docker_on $HOST pull peterbourgon/tns-db - docker_on $HOST pull alpine + weave_on $HOST setup + docker_on $HOST pull peterbourgon/tns-db + docker_on $HOST pull alpine + docker_on $HOST pull nginx done curl -sL git.io/weave -o ./weave