From be9ba707ba65983927ab12e54e06e4b0b544b907 Mon Sep 17 00:00:00 2001 From: Matt Keeler Date: Wed, 18 Dec 2019 13:45:27 -0500 Subject: [PATCH] Unflake the TestACLEndpoint_TokenList test In order to do this I added a waitForLeaderEstablishment helper which does the right thing to ensure that leader establishment has finished. fixup --- agent/consul/acl_endpoint_test.go | 1 + agent/consul/server_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/agent/consul/acl_endpoint_test.go b/agent/consul/acl_endpoint_test.go index 047f019afa..07dc654016 100644 --- a/agent/consul/acl_endpoint_test.go +++ b/agent/consul/acl_endpoint_test.go @@ -2070,6 +2070,7 @@ func TestACLEndpoint_TokenList(t *testing.T) { defer codec.Close() testrpc.WaitForLeader(t, s1.RPC, "dc1") + waitForLeaderEstablishment(t, s1) acl := ACL{srv: s1} diff --git a/agent/consul/server_test.go b/agent/consul/server_test.go index 8946a3a87c..077f154317 100644 --- a/agent/consul/server_test.go +++ b/agent/consul/server_test.go @@ -41,6 +41,21 @@ func uniqueNodeName(name string) string { return fmt.Sprintf("%s-node-%d", name, atomic.AddInt64(&id, 1)) } +// This will find the leader of a list of servers and verify that leader establishment has completed +func waitForLeaderEstablishment(t *testing.T, servers ...*Server) { + t.Helper() + retry.Run(t, func(r *retry.R) { + hasLeader := false + for _, srv := range servers { + if srv.IsLeader() { + hasLeader = true + require.True(r, srv.isReadyForConsistentReads(), "Leader %s hasn't finished establishing leadership yet", srv.config.NodeName) + } + } + require.True(r, hasLeader, "Cluster has not elected a leader yet") + }) +} + func testServerConfig(t *testing.T) (string, *Config) { dir := testutil.TempDir(t, "consul") config := DefaultConfig()