Skip to content

Commit

Permalink
integration: node removal for file discovery
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Luzzardi <[email protected]>
  • Loading branch information
Andrea Luzzardi committed May 18, 2015
1 parent d7b8734 commit 7dec704
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
8 changes: 6 additions & 2 deletions test/integration/discovery/discovery_helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
24 changes: 21 additions & 3 deletions test/integration/discovery/file.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand All @@ -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
}

0 comments on commit 7dec704

Please sign in to comment.