From 78145ecfd5a27118d73de789b1859b8224fe818c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Tisa=CC=88ter?= Date: Fri, 9 May 2014 01:17:35 +0200 Subject: [PATCH] Require datacenter argument for `WaitForLeader` --- command/agent/catalog_endpoint_test.go | 14 +++++++------- command/agent/dns_test.go | 22 +++++++++++----------- command/agent/health_endpoint_test.go | 10 +++++----- command/agent/kvs_endpoint_test.go | 8 ++++---- command/agent/local_test.go | 4 ++-- consul/leader_test.go | 2 +- testutil/wait.go | 4 ++-- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/command/agent/catalog_endpoint_test.go b/command/agent/catalog_endpoint_test.go index c9e094dcb8..d9454ab7ed 100644 --- a/command/agent/catalog_endpoint_test.go +++ b/command/agent/catalog_endpoint_test.go @@ -17,7 +17,7 @@ func TestCatalogRegister(t *testing.T) { defer srv.Shutdown() defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") // Register node req, err := http.NewRequest("GET", "/v1/catalog/register", nil) @@ -47,7 +47,7 @@ func TestCatalogDeregister(t *testing.T) { defer srv.Shutdown() defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") // Register node req, err := http.NewRequest("GET", "/v1/catalog/deregister", nil) @@ -93,7 +93,7 @@ func TestCatalogNodes(t *testing.T) { defer srv.Shutdown() defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") // Register node args := &structs.RegisterRequest{ @@ -133,7 +133,7 @@ func TestCatalogNodes_Blocking(t *testing.T) { defer srv.Shutdown() defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") // Register node args := &structs.DCSpecificRequest{ @@ -194,7 +194,7 @@ func TestCatalogServices(t *testing.T) { defer srv.Shutdown() defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") // Register node args := &structs.RegisterRequest{ @@ -236,7 +236,7 @@ func TestCatalogServiceNodes(t *testing.T) { defer srv.Shutdown() defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") // Register node args := &structs.RegisterRequest{ @@ -279,7 +279,7 @@ func TestCatalogNodeServices(t *testing.T) { defer srv.Shutdown() defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") // Register node args := &structs.RegisterRequest{ diff --git a/command/agent/dns_test.go b/command/agent/dns_test.go index 1aec2f2a0a..eeab068d9d 100644 --- a/command/agent/dns_test.go +++ b/command/agent/dns_test.go @@ -65,7 +65,7 @@ func TestDNS_NodeLookup(t *testing.T) { defer os.RemoveAll(dir) defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") // Register node args := &structs.RegisterRequest{ @@ -129,7 +129,7 @@ func TestDNS_NodeLookup_PeriodName(t *testing.T) { defer os.RemoveAll(dir) defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") // Register node with period in name args := &structs.RegisterRequest{ @@ -171,7 +171,7 @@ func TestDNS_NodeLookup_AAAA(t *testing.T) { defer os.RemoveAll(dir) defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") // Register node args := &structs.RegisterRequest{ @@ -213,7 +213,7 @@ func TestDNS_NodeLookup_CNAME(t *testing.T) { defer os.RemoveAll(dir) defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") // Register node args := &structs.RegisterRequest{ @@ -256,7 +256,7 @@ func TestDNS_ServiceLookup(t *testing.T) { defer os.RemoveAll(dir) defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") // Register node args := &structs.RegisterRequest{ @@ -317,7 +317,7 @@ func TestDNS_ServiceLookup_TagPeriod(t *testing.T) { defer os.RemoveAll(dir) defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") // Register node args := &structs.RegisterRequest{ @@ -378,7 +378,7 @@ func TestDNS_ServiceLookup_Dedup(t *testing.T) { defer os.RemoveAll(dir) defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") // Register node args := &structs.RegisterRequest{ @@ -455,7 +455,7 @@ func TestDNS_ServiceLookup_Dedup_SRV(t *testing.T) { defer os.RemoveAll(dir) defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") // Register node args := &structs.RegisterRequest{ @@ -584,7 +584,7 @@ func TestDNS_ServiceLookup_FilterCritical(t *testing.T) { defer os.RemoveAll(dir) defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") // Register nodes args := &structs.RegisterRequest{ @@ -648,7 +648,7 @@ func TestDNS_ServiceLookup_Randomize(t *testing.T) { defer os.RemoveAll(dir) defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") // Register nodes for i := 0; i < 3*maxServiceResponses; i++ { @@ -712,7 +712,7 @@ func TestDNS_ServiceLookup_CNAME(t *testing.T) { defer os.RemoveAll(dir) defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") // Register node args := &structs.RegisterRequest{ diff --git a/command/agent/health_endpoint_test.go b/command/agent/health_endpoint_test.go index 4a097ae65d..910d37df8b 100644 --- a/command/agent/health_endpoint_test.go +++ b/command/agent/health_endpoint_test.go @@ -16,7 +16,7 @@ func TestHealthChecksInState(t *testing.T) { defer srv.Shutdown() defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") req, err := http.NewRequest("GET", "/v1/health/state/passing?dc=dc1", nil) if err != nil { @@ -43,7 +43,7 @@ func TestHealthNodeChecks(t *testing.T) { defer srv.Shutdown() defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") req, err := http.NewRequest("GET", fmt.Sprintf("/v1/health/node/%s?dc=dc1", srv.agent.config.NodeName), nil) @@ -71,7 +71,7 @@ func TestHealthServiceChecks(t *testing.T) { defer srv.Shutdown() defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") // Create a service check args := &structs.RegisterRequest{ @@ -115,7 +115,7 @@ func TestHealthServiceNodes(t *testing.T) { defer srv.Shutdown() defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") req, err := http.NewRequest("GET", "/v1/health/service/consul?dc=dc1", nil) if err != nil { @@ -142,7 +142,7 @@ func TestHealthServiceNodes_PassingFilter(t *testing.T) { defer srv.Shutdown() defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") // Create a failing service check args := &structs.RegisterRequest{ diff --git a/command/agent/kvs_endpoint_test.go b/command/agent/kvs_endpoint_test.go index 3ccc12bdff..61216faafc 100644 --- a/command/agent/kvs_endpoint_test.go +++ b/command/agent/kvs_endpoint_test.go @@ -18,7 +18,7 @@ func TestKVSEndpoint_PUT_GET_DELETE(t *testing.T) { defer srv.Shutdown() defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") keys := []string{ "baz", @@ -93,7 +93,7 @@ func TestKVSEndpoint_Recurse(t *testing.T) { defer srv.Shutdown() defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") keys := []string{ "bar", @@ -189,7 +189,7 @@ func TestKVSEndpoint_CAS(t *testing.T) { defer srv.Shutdown() defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") { buf := bytes.NewBuffer([]byte("test")) @@ -286,7 +286,7 @@ func TestKVSEndpoint_ListKeys(t *testing.T) { defer srv.Shutdown() defer srv.agent.Shutdown() - testutil.WaitForLeader(t, srv.agent.RPC) + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") keys := []string{ "bar", diff --git a/command/agent/local_test.go b/command/agent/local_test.go index 2eed35d68d..9ce16fed31 100644 --- a/command/agent/local_test.go +++ b/command/agent/local_test.go @@ -15,7 +15,7 @@ func TestAgentAntiEntropy_Services(t *testing.T) { defer os.RemoveAll(dir) defer agent.Shutdown() - testutil.WaitForLeader(t, agent.RPC) + testutil.WaitForLeader(t, agent.RPC, "dc1") // Register info args := &structs.RegisterRequest{ @@ -137,7 +137,7 @@ func TestAgentAntiEntropy_Checks(t *testing.T) { defer os.RemoveAll(dir) defer agent.Shutdown() - testutil.WaitForLeader(t, agent.RPC) + testutil.WaitForLeader(t, agent.RPC, "dc1") // Register info args := &structs.RegisterRequest{ diff --git a/consul/leader_test.go b/consul/leader_test.go index 09e1856e51..f5b56174eb 100644 --- a/consul/leader_test.go +++ b/consul/leader_test.go @@ -20,7 +20,7 @@ func TestLeader_RegisterMember(t *testing.T) { defer c1.Shutdown() client := rpcClient(t, s1) - testutil.WaitForLeader(t, client.Call) + testutil.WaitForLeader(t, client.Call, "dc1") // Try to join addr := fmt.Sprintf("127.0.0.1:%d", diff --git a/testutil/wait.go b/testutil/wait.go index 20ab8ea5e5..7eb49a8e4d 100644 --- a/testutil/wait.go +++ b/testutil/wait.go @@ -29,11 +29,11 @@ func WaitForResult(test testFn, error errorFn) { type rpcFn func(string, interface {}, interface {}) error -func WaitForLeader(t *testing.T, rpc rpcFn) structs.IndexedNodes { +func WaitForLeader(t *testing.T, rpc rpcFn, dc string) structs.IndexedNodes { var out structs.IndexedNodes WaitForResult(func() (bool, error) { args := &structs.RegisterRequest{ - Datacenter: "dc1", + Datacenter: dc, } err := rpc("Catalog.ListNodes", args, &out) return out.QueryMeta.KnownLeader, err