From 7dec704b8aff9bcc40b2d7d73d42a5a5e399b903 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Sat, 16 May 2015 21:33:43 -0700 Subject: [PATCH] integration: node removal for file discovery Signed-off-by: Andrea Luzzardi --- .../discovery/discovery_helpers.bash | 8 +++++-- test/integration/discovery/file.bats | 24 ++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/test/integration/discovery/discovery_helpers.bash b/test/integration/discovery/discovery_helpers.bash index 13597a6aa9..e080b90fdc 100644 --- a/test/integration/discovery/discovery_helpers.bash +++ b/test/integration/discovery/discovery_helpers.bash @@ -4,13 +4,17 @@ load ../helpers # Returns true if all nodes have joined the swarm. function discovery_check_swarm_info() { - docker_swarm info | grep -q "Nodes: ${#HOSTS[@]}" + local total="$1" + [ -z "$total" ] && total="${#HOSTS[@]}" + + docker_swarm info | grep -q "Nodes: $count" } # Returns true if all nodes have joined the discovery. function discovery_check_swarm_list() { local joined=`swarm list "$1" | wc -l` - local total=${#HOSTS[@]} + local total="$2" + [ -z "$total" ] && total="${#HOSTS[@]}" echo "${joined} out of ${total} hosts joined discovery" [ "$joined" -eq "$total" ] diff --git a/test/integration/discovery/file.bats b/test/integration/discovery/file.bats index 5fa5989b99..35bb1709fc 100644 --- a/test/integration/discovery/file.bats +++ b/test/integration/discovery/file.bats @@ -31,7 +31,7 @@ function setup_discovery_file() { # Start 2 engines and register them in the file. start_docker 2 setup_discovery_file - retry 5 1 discovery_check_swarm_list "$DISCOVERY" + discovery_check_swarm_list "$DISCOVERY" # Then, start a manager and ensure it sees all the engines. swarm_manage "$DISCOVERY" @@ -49,10 +49,28 @@ function setup_discovery_file() { # Add engines to the cluster and make sure it's picked up by swarm. start_docker 2 setup_discovery_file - retry 5 1 discovery_check_swarm_list "$DISCOVERY" + discovery_check_swarm_list "$DISCOVERY" retry 5 1 discovery_check_swarm_info } +@test "file discovery: node removal" { + # The goal of this test is to ensure swarm can handle node removal. + + # Start 2 engines and register them in the file. + start_docker 2 + setup_discovery_file + discovery_check_swarm_list "$DISCOVERY" + + # Then, start a manager and ensure it sees all the engines. + swarm_manage "$DISCOVERY" + retry 5 1 discovery_check_swarm_info + + # Update the file with only one engine and see if swarm picks it up. + echo ${HOSTS[0]} > $DISCOVERY_FILE + discovery_check_swarm_list "$DISCOVERY" 1 + retry 5 1 discovery_check_swarm_info 1 +} + @test "file discovery: failure" { # The goal of this test is to simulate a failure (file not available) and ensure discovery # is resilient to it. @@ -70,6 +88,6 @@ function setup_discovery_file() { setup_discovery_file # After a while, `join` and `manage` should see the file. - retry 5 1 discovery_check_swarm_list "$DISCOVERY" + discovery_check_swarm_list "$DISCOVERY" retry 5 1 discovery_check_swarm_info }