From 98c36bb683316a4d106dedd96bc752b2d8a4e3fe Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Thu, 26 Oct 2023 22:10:16 -0700 Subject: [PATCH] oh no rsa nooooo --- testutil/wait.go | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/testutil/wait.go b/testutil/wait.go index 3466f497b39..9d07c47a47b 100644 --- a/testutil/wait.go +++ b/testutil/wait.go @@ -138,10 +138,27 @@ type rpcFn func(string, interface{}, interface{}) error func WaitForLeader(t testing.TB, rpc rpcFn) { t.Helper() WaitForResult(func() (bool, error) { - args := &structs.GenericRequest{} + args := &structs.GenericRequest{ + QueryOptions: structs.QueryOptions{ + Namespace: "default", + Region: "global", + }, + } var leader string err := rpc("Status.Leader", args, &leader) - return leader != "", err + if err != nil { + return leader != "", err + } + if leader == "" { + return false, err + } + + // As of 1.7 the RSA key generation slows down keyring initialization so + // much that tests relying on the keyring being initialized fail unless + // they wait until the key was generated + var resp structs.KeyringListPublicResponse + err = rpc("Keyring.ListPublic", args, &resp) + return err == nil, err }, func(err error) { t.Fatalf("failed to find leader: %v", err) }) @@ -154,10 +171,27 @@ func WaitForLeaders(t testing.TB, rpcs ...rpcFn) string { var leader string for i := 0; i < len(rpcs); i++ { ok := func() (bool, error) { - leader = "" - args := &structs.GenericRequest{} + args := &structs.GenericRequest{ + QueryOptions: structs.QueryOptions{ + Namespace: "default", + Region: "global", + }, + } + var leader string err := rpcs[i]("Status.Leader", args, &leader) - return leader != "", err + if err != nil { + return leader != "", err + } + if leader == "" { + return false, err + } + + // As of 1.7 the RSA key generation slows down keyring initialization so + // much that tests relying on the keyring being initialized fail unless + // they wait until the key was generated + var resp structs.KeyringListPublicResponse + err = rpcs[i]("Keyring.ListPublic", args, &resp) + return err == nil, err } must.Wait(t, wait.InitialSuccess( wait.TestFunc(ok),