Skip to content
This repository has been archived by the owner on Feb 1, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1466 from abronan/fix_ci_discovery_race
Browse files Browse the repository at this point in the history
Integration: Wait for nodes to be registered and discovered before testing
  • Loading branch information
vieux committed Dec 8, 2015
2 parents 67a4d55 + f1b7b7b commit a4a1d3b
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion test/integration/discovery/consul.bats
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function teardown() {
swarm_join "$DISCOVERY"

# Start a manager. It should keep retrying
swarm_manage "$DISCOVERY"
swarm_manage_no_wait "$DISCOVERY"

# Now start the store
start_store
Expand Down
8 changes: 0 additions & 8 deletions test/integration/discovery/discovery_helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@

load ../helpers

# Returns true if all nodes have joined the swarm.
function discovery_check_swarm_info() {
local total="$1"
[ -z "$total" ] && total="${#HOSTS[@]}"

docker_swarm info | grep -q "Nodes: $total"
}

# Returns true if swarm info outputs is empty (0 nodes).
function discovery_check_swarm_info_empty() {
docker_swarm info | grep -q "Nodes: 0"
Expand Down
2 changes: 1 addition & 1 deletion test/integration/discovery/etcd.bats
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function teardown() {
swarm_join "$DISCOVERY"

# Start a manager. It should keep retrying
swarm_manage "$DISCOVERY"
swarm_manage_no_wait "$DISCOVERY"

# Now start the store
start_store
Expand Down
2 changes: 1 addition & 1 deletion test/integration/discovery/file.bats
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function setup_discovery_file() {
start_docker 2

# Start a manager. It should keep retrying
swarm_manage "$DISCOVERY"
swarm_manage_no_wait "$DISCOVERY"

# Now create the discovery file.
setup_discovery_file
Expand Down
2 changes: 1 addition & 1 deletion test/integration/discovery/zk.bats
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function teardown() {
swarm_join "$DISCOVERY"

# Start a manager. It should keep retrying
swarm_manage "$DISCOVERY"
swarm_manage_no_wait "$DISCOVERY"

# Now start the store
start_store
Expand Down
23 changes: 22 additions & 1 deletion test/integration/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,27 @@ function wait_until_reachable() {
retry 10 1 docker -H $1 info
}

# Start the swarm manager in background.
# Returns true if all nodes have joined the swarm.
function discovery_check_swarm_info() {
local total="$1"
[ -z "$total" ] && total="${#HOSTS[@]}"
local host="$2"
[ -z "$host" ] && host="${SWARM_HOSTS[0]}"

retry 10 1 eval "docker -H $host info | grep -q -e \"Nodes: $total\" -e \"Offers: $total\""
}

function swarm_manage() {
local i=${#SWARM_MANAGE_PID[@]}

swarm_manage_no_wait "$@"

# Wait for nodes to be discovered
discovery_check_swarm_info "${#HOSTS[@]}" "${SWARM_HOSTS[$i]}"
}

# Start the swarm manager in background.
function swarm_manage_no_wait() {
local discovery
if [ $# -eq 0 ]; then
discovery=`join , ${HOSTS[@]}`
Expand All @@ -101,6 +120,8 @@ function swarm_manage() {
"$SWARM_BINARY" -l debug manage -H "$host" --heartbeat=1s $discovery &
SWARM_MANAGE_PID[$i]=$!
SWARM_HOSTS[$i]=$host

# Wait for the Manager to be reachable
wait_until_reachable "$host"
}

Expand Down
1 change: 0 additions & 1 deletion test/integration/mesos/zk/zk.bats
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ function teardown() {
start_mesos_zk $DISCOVERY

swarm_manage --cluster-driver mesos-experimental $DISCOVERY
sleep 5

run docker_swarm info
[ "$status" -eq 0 ]
Expand Down

0 comments on commit a4a1d3b

Please sign in to comment.