Skip to content

Commit

Permalink
oh no rsa nooooo
Browse files Browse the repository at this point in the history
  • Loading branch information
schmichael committed Oct 27, 2023
1 parent acda651 commit 98c36bb
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions testutil/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand All @@ -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),
Expand Down

0 comments on commit 98c36bb

Please sign in to comment.