From 63492feb3fc12c8e8bb24000f339b23b48709e38 Mon Sep 17 00:00:00 2001 From: Sriram Natarajan Date: Thu, 7 May 2015 00:42:52 +0000 Subject: [PATCH] Integration test for consul discovery service Signed-off-by: Sriram Natarajan --- test/integration/discovery-consul.bats | 52 ++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 test/integration/discovery-consul.bats diff --git a/test/integration/discovery-consul.bats b/test/integration/discovery-consul.bats new file mode 100644 index 0000000000..1d5c42535b --- /dev/null +++ b/test/integration/discovery-consul.bats @@ -0,0 +1,52 @@ +#!/usr/bin/env bats + +load helpers + +# Address on which Consul will listen (random port between 8000 and 9000). +CONSUL_HOST=127.0.0.1:$(( ( RANDOM % 1000 ) + 8000 )) + +# Container name for integration test +CONTAINER_NAME=swarm_consul + +function check_leader() { + # Confirm Cluster leader election + docker_host logs $CONTAINER_NAME | grep "New leader elected" + # Check member state + docker_host logs $CONTAINER_NAME | grep "consul: member '$CONTAINER_NAME' joined, marking health alive" +} + +function start_consul() { + docker_host run --name=$CONTAINER_NAME -h $CONTAINER_NAME -p $CONSUL_HOST:8500 -d progrium/consul -server -bootstrap-expect 1 -data-dir /test + # Check if consul cluster leader is elected + retry 30 1 check_leader +} + +function stop_consul() { + docker_host rm -f -v $CONTAINER_NAME +} + +function setup() { + start_consul +} + +function teardown() { + swarm_manage_cleanup + swarm_join_cleanup + stop_docker + stop_consul +} + +@test "consul discovery" { + # Start 2 engines and make them join the cluster. + start_docker 2 + swarm_join "consul://${CONSUL_HOST}/test" + + # Start a manager and ensure it sees all the engines. + swarm_manage "consul://${CONSUL_HOST}/test" + check_swarm_nodes + + # Add another engine to the cluster and make sure it's picked up by swarm. + start_docker 1 + swarm_join "consul://${CONSUL_HOST}/test" + retry 30 1 check_swarm_nodes +}