From d97c06207d50fe0f930b8fe772b51575a1333805 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Mon, 22 Feb 2016 16:57:19 -0800 Subject: [PATCH] add a reschedule test with compose Signed-off-by: Victor Vieux --- test/integration/compose/up.bats | 51 +++++++++++++++++++ .../testdata/compose/reschedule.yml | 14 +++++ 2 files changed, 65 insertions(+) create mode 100644 test/integration/testdata/compose/reschedule.yml diff --git a/test/integration/compose/up.bats b/test/integration/compose/up.bats index c45389252a..11b0a4de05 100644 --- a/test/integration/compose/up.bats +++ b/test/integration/compose/up.bats @@ -47,3 +47,54 @@ function teardown() { # check memory-swappiness [[ "${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 ] +} diff --git a/test/integration/testdata/compose/reschedule.yml b/test/integration/testdata/compose/reschedule.yml new file mode 100644 index 0000000000..0e60203c0b --- /dev/null +++ b/test/integration/testdata/compose/reschedule.yml @@ -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"]'