From e9f773f10f8c10aa345de4d2c09d174bd0cd8f6a Mon Sep 17 00:00:00 2001 From: Sriram Natarajan Date: Mon, 11 May 2015 18:58:21 +0000 Subject: [PATCH] Etcd Integration test Signed-off-by: Sriram Natarajan --- test/integration/discovery-etcd.bats | 52 ++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 test/integration/discovery-etcd.bats diff --git a/test/integration/discovery-etcd.bats b/test/integration/discovery-etcd.bats new file mode 100644 index 0000000000..19c2ba9301 --- /dev/null +++ b/test/integration/discovery-etcd.bats @@ -0,0 +1,52 @@ +#!/usr/bin/env bats + +load helpers + +# Address on which Etcd will listen (random port between 9000 and 10,000). +ETCD_HOST=127.0.0.1:$(( ( RANDOM % 1000 ) + 9000 )) + +# Container name for integration test +CONTAINER_NAME=swarm_etcd + +function check_leader() { + # Confirm Cluster leader election + docker_host logs $CONTAINER_NAME | grep "state changed from 'follower' to 'leader'" + # Check leader event + docker_host logs $CONTAINER_NAME | grep "leader changed from '' to" +} + +function start_etcd() { + docker_host run -p $ETCD_HOST:4001 --name=$CONTAINER_NAME -d coreos/etcd + # Check if etcd cluster leader is elected + retry 30 1 check_leader +} + +function stop_etcd() { + docker_host rm -f -v $CONTAINER_NAME +} + +function setup() { + start_etcd +} + +function teardown() { + swarm_manage_cleanup + swarm_join_cleanup + stop_docker + stop_etcd +} + +@test "etcd discovery" { + # Start 2 engines and make them join the cluster. + start_docker 2 + swarm_join "etcd://${ETCD_HOST}/test" + + # Start a manager and ensure it sees all the engines. + swarm_manage "etcd://${ETCD_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 "etcd://${ETCD_HOST}/test" + retry 30 1 check_swarm_nodes +}