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
This commit is contained in:
Matt Keeler 2019-12-18 13:45:27 -05:00
parent 8af12bf4f4
commit 185654b075
No known key found for this signature in database
GPG Key ID: 04DBAE1857E0081B
2 changed files with 16 additions and 0 deletions

View File

@ -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}

View File

@ -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()