From 22dcdc245d52aa7e39a17f35175a0e11f3ea3a2b Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Tue, 28 Jul 2015 18:26:17 -0700 Subject: [PATCH] integration helpers: Allow to run multiple managers. Signed-off-by: Andrea Luzzardi --- test/integration/helpers.bash | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/test/integration/helpers.bash b/test/integration/helpers.bash index 787e6b876d..b2ceffa6d1 100644 --- a/test/integration/helpers.bash +++ b/test/integration/helpers.bash @@ -17,8 +17,8 @@ DOCKER_IMAGE=${DOCKER_IMAGE:-dockerswarm/dind-master} DOCKER_VERSION=${DOCKER_VERSION:-latest} DOCKER_BINARY=${DOCKER_BINARY:-`command -v docker`} -# Host on which the manager will listen to (random port between 6000 and 7000). -SWARM_HOST=127.0.0.1:$(( ( RANDOM % 1000 ) + 6000 )) +# Port on which the manager will listen to (random port between 6000 and 7000). +SWARM_BASE_PORT=$(( ( RANDOM % 1000 ) + 6000 )) # Use a random base port (for engines) between 5000 and 6000. BASE_PORT=$(( ( RANDOM % 1000 ) + 5000 )) @@ -50,7 +50,7 @@ function docker_host() { # Run the docker CLI against swarm. function docker_swarm() { - docker -H $SWARM_HOST "$@" + docker -H ${SWARM_HOSTS[0]} "$@" } # Run the swarm binary. You must NOT fork this command (swarm foo &) as the PID @@ -94,9 +94,15 @@ function swarm_manage() { discovery="$@" fi - "$SWARM_BINARY" -l debug manage -H "$SWARM_HOST" --heartbeat=1s "$discovery" & - SWARM_PID=$! - wait_until_reachable "$SWARM_HOST" + local i=${#SWARM_MANAGE_PID[@]} + local port=$(($SWARM_BASE_PORT + $i)) + local host=127.0.0.1:$port + + echo "$SWARM_BINARY" -l debug manage -H "$host" --heartbeat=1s $discovery + "$SWARM_BINARY" -l debug manage -H "$host" --heartbeat=1s $discovery & + SWARM_MANAGE_PID[$i]=$! + SWARM_HOSTS[$i]=$host + wait_until_reachable "$host" } # swarm join every engine created with `start_docker`. @@ -124,7 +130,9 @@ function swarm_join() { # Stops the manager. function swarm_manage_cleanup() { - kill $SWARM_PID || true + for pid in ${SWARM_MANAGE_PID[@]}; do + kill $pid || true + done } # Clean up Swarm join processes