From 93c7103bb54bcc0c26ff80a05bd9b37d03c6cf96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Tis=C3=A4ter?= Date: Wed, 7 May 2014 23:47:16 +0200 Subject: [PATCH] Move `WaitForLeader` calls to top of test --- command/agent/dns_test.go | 44 +++++++++++++-------------- command/agent/health_endpoint_test.go | 12 ++++---- command/agent/local_test.go | 14 +++++---- consul/catalog_endpoint_test.go | 6 ++-- 4 files changed, 39 insertions(+), 37 deletions(-) diff --git a/command/agent/dns_test.go b/command/agent/dns_test.go index f1b0ba46a3..1aec2f2a0a 100644 --- a/command/agent/dns_test.go +++ b/command/agent/dns_test.go @@ -65,6 +65,8 @@ func TestDNS_NodeLookup(t *testing.T) { defer os.RemoveAll(dir) defer srv.agent.Shutdown() + testutil.WaitForLeader(t, srv.agent.RPC) + // Register node args := &structs.RegisterRequest{ Datacenter: "dc1", @@ -72,8 +74,6 @@ func TestDNS_NodeLookup(t *testing.T) { Address: "127.0.0.1", } - testutil.WaitForLeader(t, srv.agent.RPC) - var out struct{} if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil { t.Fatalf("err: %v", err) @@ -129,6 +129,8 @@ func TestDNS_NodeLookup_PeriodName(t *testing.T) { defer os.RemoveAll(dir) defer srv.agent.Shutdown() + testutil.WaitForLeader(t, srv.agent.RPC) + // Register node with period in name args := &structs.RegisterRequest{ Datacenter: "dc1", @@ -136,8 +138,6 @@ func TestDNS_NodeLookup_PeriodName(t *testing.T) { Address: "127.0.0.1", } - testutil.WaitForLeader(t, srv.agent.RPC) - var out struct{} if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil { t.Fatalf("err: %v", err) @@ -171,6 +171,8 @@ func TestDNS_NodeLookup_AAAA(t *testing.T) { defer os.RemoveAll(dir) defer srv.agent.Shutdown() + testutil.WaitForLeader(t, srv.agent.RPC) + // Register node args := &structs.RegisterRequest{ Datacenter: "dc1", @@ -178,8 +180,6 @@ func TestDNS_NodeLookup_AAAA(t *testing.T) { Address: "::4242:4242", } - testutil.WaitForLeader(t, srv.agent.RPC) - var out struct{} if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil { t.Fatalf("err: %v", err) @@ -213,6 +213,8 @@ func TestDNS_NodeLookup_CNAME(t *testing.T) { defer os.RemoveAll(dir) defer srv.agent.Shutdown() + testutil.WaitForLeader(t, srv.agent.RPC) + // Register node args := &structs.RegisterRequest{ Datacenter: "dc1", @@ -220,8 +222,6 @@ func TestDNS_NodeLookup_CNAME(t *testing.T) { Address: "www.google.com", } - testutil.WaitForLeader(t, srv.agent.RPC) - var out struct{} if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil { t.Fatalf("err: %v", err) @@ -256,6 +256,8 @@ func TestDNS_ServiceLookup(t *testing.T) { defer os.RemoveAll(dir) defer srv.agent.Shutdown() + testutil.WaitForLeader(t, srv.agent.RPC) + // Register node args := &structs.RegisterRequest{ Datacenter: "dc1", @@ -268,8 +270,6 @@ func TestDNS_ServiceLookup(t *testing.T) { }, } - testutil.WaitForLeader(t, srv.agent.RPC) - var out struct{} if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil { t.Fatalf("err: %v", err) @@ -317,6 +317,8 @@ func TestDNS_ServiceLookup_TagPeriod(t *testing.T) { defer os.RemoveAll(dir) defer srv.agent.Shutdown() + testutil.WaitForLeader(t, srv.agent.RPC) + // Register node args := &structs.RegisterRequest{ Datacenter: "dc1", @@ -329,8 +331,6 @@ func TestDNS_ServiceLookup_TagPeriod(t *testing.T) { }, } - testutil.WaitForLeader(t, srv.agent.RPC) - var out struct{} if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil { t.Fatalf("err: %v", err) @@ -378,6 +378,8 @@ func TestDNS_ServiceLookup_Dedup(t *testing.T) { defer os.RemoveAll(dir) defer srv.agent.Shutdown() + testutil.WaitForLeader(t, srv.agent.RPC) + // Register node args := &structs.RegisterRequest{ Datacenter: "dc1", @@ -390,8 +392,6 @@ func TestDNS_ServiceLookup_Dedup(t *testing.T) { }, } - testutil.WaitForLeader(t, srv.agent.RPC) - var out struct{} if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil { t.Fatalf("err: %v", err) @@ -455,6 +455,8 @@ func TestDNS_ServiceLookup_Dedup_SRV(t *testing.T) { defer os.RemoveAll(dir) defer srv.agent.Shutdown() + testutil.WaitForLeader(t, srv.agent.RPC) + // Register node args := &structs.RegisterRequest{ Datacenter: "dc1", @@ -467,8 +469,6 @@ func TestDNS_ServiceLookup_Dedup_SRV(t *testing.T) { }, } - testutil.WaitForLeader(t, srv.agent.RPC) - var out struct{} if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil { t.Fatalf("err: %v", err) @@ -584,6 +584,8 @@ func TestDNS_ServiceLookup_FilterCritical(t *testing.T) { defer os.RemoveAll(dir) defer srv.agent.Shutdown() + testutil.WaitForLeader(t, srv.agent.RPC) + // Register nodes args := &structs.RegisterRequest{ Datacenter: "dc1", @@ -601,8 +603,6 @@ func TestDNS_ServiceLookup_FilterCritical(t *testing.T) { }, } - testutil.WaitForLeader(t, srv.agent.RPC) - var out struct{} if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil { t.Fatalf("err: %v", err) @@ -648,6 +648,8 @@ func TestDNS_ServiceLookup_Randomize(t *testing.T) { defer os.RemoveAll(dir) defer srv.agent.Shutdown() + testutil.WaitForLeader(t, srv.agent.RPC) + // Register nodes for i := 0; i < 3*maxServiceResponses; i++ { args := &structs.RegisterRequest{ @@ -660,8 +662,6 @@ func TestDNS_ServiceLookup_Randomize(t *testing.T) { }, } - testutil.WaitForLeader(t, srv.agent.RPC) - var out struct{} if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil { t.Fatalf("err: %v", err) @@ -712,6 +712,8 @@ func TestDNS_ServiceLookup_CNAME(t *testing.T) { defer os.RemoveAll(dir) defer srv.agent.Shutdown() + testutil.WaitForLeader(t, srv.agent.RPC) + // Register node args := &structs.RegisterRequest{ Datacenter: "dc1", @@ -723,8 +725,6 @@ func TestDNS_ServiceLookup_CNAME(t *testing.T) { }, } - testutil.WaitForLeader(t, srv.agent.RPC) - var out struct{} if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil { t.Fatalf("err: %v", err) diff --git a/command/agent/health_endpoint_test.go b/command/agent/health_endpoint_test.go index 10f84be9d0..4a097ae65d 100644 --- a/command/agent/health_endpoint_test.go +++ b/command/agent/health_endpoint_test.go @@ -71,6 +71,9 @@ func TestHealthServiceChecks(t *testing.T) { defer srv.Shutdown() defer srv.agent.Shutdown() + testutil.WaitForLeader(t, srv.agent.RPC) + + // Create a service check args := &structs.RegisterRequest{ Datacenter: "dc1", Node: srv.agent.config.NodeName, @@ -82,9 +85,6 @@ func TestHealthServiceChecks(t *testing.T) { }, } - testutil.WaitForLeader(t, srv.agent.RPC) - - // Create a service check var out struct{} if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil { t.Fatalf("err: %v", err) @@ -142,6 +142,9 @@ func TestHealthServiceNodes_PassingFilter(t *testing.T) { defer srv.Shutdown() defer srv.agent.Shutdown() + testutil.WaitForLeader(t, srv.agent.RPC) + + // Create a failing service check args := &structs.RegisterRequest{ Datacenter: "dc1", Node: srv.agent.config.NodeName, @@ -154,9 +157,6 @@ func TestHealthServiceNodes_PassingFilter(t *testing.T) { }, } - testutil.WaitForLeader(t, srv.agent.RPC) - - // Create a failing service check var out struct{} if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil { t.Fatalf("err: %v", err) diff --git a/command/agent/local_test.go b/command/agent/local_test.go index 69a85a8e5e..2eed35d68d 100644 --- a/command/agent/local_test.go +++ b/command/agent/local_test.go @@ -15,15 +15,16 @@ func TestAgentAntiEntropy_Services(t *testing.T) { defer os.RemoveAll(dir) defer agent.Shutdown() + testutil.WaitForLeader(t, agent.RPC) + + // Register info args := &structs.RegisterRequest{ Datacenter: "dc1", Node: agent.config.NodeName, Address: "127.0.0.1", } - testutil.WaitForLeader(t, agent.RPC) - - // Register info. Exists both, same (noop) + // Exists both, same (noop) var out struct{} srv1 := &structs.NodeService{ ID: "mysql", @@ -136,15 +137,16 @@ func TestAgentAntiEntropy_Checks(t *testing.T) { defer os.RemoveAll(dir) defer agent.Shutdown() + testutil.WaitForLeader(t, agent.RPC) + + // Register info args := &structs.RegisterRequest{ Datacenter: "dc1", Node: agent.config.NodeName, Address: "127.0.0.1", } - testutil.WaitForLeader(t, agent.RPC) - - // Register info. Exists both, same (noop) + // Exists both, same (noop) var out struct{} chk1 := &structs.HealthCheck{ Node: agent.config.NodeName, diff --git a/consul/catalog_endpoint_test.go b/consul/catalog_endpoint_test.go index 66059b5e75..4c5a2c70b4 100644 --- a/consul/catalog_endpoint_test.go +++ b/consul/catalog_endpoint_test.go @@ -254,14 +254,14 @@ func TestCatalogListNodes_StaleRaad(t *testing.T) { t.Fatalf("err: %v", err) } + testutil.WaitForLeader(t, client1.Call) + testutil.WaitForLeader(t, client2.Call) + args := structs.DCSpecificRequest{ Datacenter: "dc1", QueryOptions: structs.QueryOptions{AllowStale: true}, } - testutil.WaitForLeader(t, client1.Call) - testutil.WaitForLeader(t, client2.Call) - // Use the follower as the client var client *rpc.Client if !s1.IsLeader() {