add a reschedule test with compose

Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
Victor Vieux 2016-02-22 16:57:19 -08:00
parent c363c31608
commit d97c06207d
2 changed files with 65 additions and 0 deletions

View File

@ -47,3 +47,54 @@ function teardown() {
# check memory-swappiness # check memory-swappiness
[[ "${output}" == *"->80/tcp"* ]] [[ "${output}" == *"->80/tcp"* ]]
} }
function containerRunning() {
local container="$1"
local node="$2"
run docker_swarm inspect "$container"
[ "$status" -eq 0 ]
[[ "${output}" == *"\"Name\": \"$node\""* ]]
[[ "${output}" == *"\"Status\": \"running\""* ]]
}
@test "docker-compose up - reschedule" {
start_docker_with_busybox 2
swarm_manage --engine-refresh-min-interval=1s --engine-refresh-max-interval=1s --engine-failure-retry=1 ${HOSTS[0]},${HOSTS[1]}
FILE=$TESTDATA/compose/reschedule.yml
docker-compose_swarm -f $FILE up -d
run docker_swarm ps -q
[ "${#lines[@]}" -eq 2 ]
# Make sure containers are running where they should.
containerRunning "compose_service1_1" "node-0"
containerRunning "compose_service2_1" "node-0"
# Get service1 swarm id
swarm_id=$(docker_swarm inspect -f '{{ index .Config.Labels "com.docker.swarm.id" }}' compose_service1_1)
# Stop node-0
docker_host kill ${DOCKER_CONTAINERS[0]}
# Wait for Swarm to detect the node failure.
retry 5 1 eval "docker_swarm info | grep -q 'Unhealthy'"
# Wait for the container to be rescheduled
# service1 should have been rescheduled from node-0 to node-1
retry 5 1 containerRunning "compose_service1_1" "node-1"
# Check swarm id didn't change for service1
[[ "$swarm_id" == $(docker_swarm inspect -f '{{ index .Config.Labels "com.docker.swarm.id" }}' compose_service1_1) ]]
run docker_swarm inspect "$swarm_id"
[ "$status" -eq 0 ]
[[ "${output}" == *'"Name": "node-1"'* ]]
# service_2 should still be on node-0 since the rescheduling policy was off.
run docker_swarm inspect compose_service2_1
[ "$status" -eq 1 ]
run docker_swarm ps -q
[ "${#lines[@]}" -eq 1 ]
}

View File

@ -0,0 +1,14 @@
service1:
image: busybox
ports:
- "80"
command: sleep 100
labels:
com.docker.swarm.constraints: '["node==~node-0"]'
com.docker.swarm.reschedule-policies: '["on-node-failure"]'
service2:
image: busybox
command: sleep 100
labels:
com.docker.swarm.constraints: '["node==~node-0"]'