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 }