diff --git a/command/agent/local_test.go b/command/agent/local_test.go index a84c1a2929..8c3f8bda96 100644 --- a/command/agent/local_test.go +++ b/command/agent/local_test.go @@ -1,6 +1,7 @@ package agent import ( + "github.com/hashicorp/consul/testutil" "github.com/hashicorp/consul/consul/structs" "os" "reflect" @@ -14,18 +15,16 @@ func TestAgentAntiEntropy_Services(t *testing.T) { defer os.RemoveAll(dir) defer agent.Shutdown() - // Wait for a leader - time.Sleep(100 * time.Millisecond) - - // Register info args := &structs.RegisterRequest{ Datacenter: "dc1", Node: agent.config.NodeName, Address: "127.0.0.1", } - var out struct{} - // Exists both, same (noop) + testutil.WaitForLeader(t, agent.RPC, args) + + // Register info. Exists both, same (noop) + var out struct{} srv1 := &structs.NodeService{ ID: "mysql", Service: "mysql", @@ -137,18 +136,16 @@ func TestAgentAntiEntropy_Checks(t *testing.T) { defer os.RemoveAll(dir) defer agent.Shutdown() - // Wait for a leader - time.Sleep(100 * time.Millisecond) - - // Register info args := &structs.RegisterRequest{ Datacenter: "dc1", Node: agent.config.NodeName, Address: "127.0.0.1", } - var out struct{} - // Exists both, same (noop) + testutil.WaitForLeader(t, agent.RPC, args) + + // Register info. Exists both, same (noop) + var out struct{} chk1 := &structs.HealthCheck{ Node: agent.config.NodeName, CheckID: "mysql",