ca: remove duplicate WaitFor function

This commit is contained in:
Daniel Nephin 2021-12-08 12:35:36 -05:00
parent 1dec6bb815
commit 305655a8b1
3 changed files with 7 additions and 25 deletions

View File

@ -697,8 +697,8 @@ func TestConnectCAConfig_UpdateSecondary(t *testing.T) {
require.Len(rootList.Roots, 1)
rootCert := activeRoot
waitForActiveCARoot(t, s1, rootCert)
waitForActiveCARoot(t, s2, rootCert)
testrpc.WaitForActiveCARoot(t, s1.RPC, "primary", rootCert)
testrpc.WaitForActiveCARoot(t, s2.RPC, "secondary", rootCert)
// Capture the current intermediate
rootList, activeRoot, err = getTestRoots(s2, "secondary")

View File

@ -314,18 +314,6 @@ func TestCAManager_Initialize_Secondary(t *testing.T) {
}
}
func waitForActiveCARoot(t *testing.T, srv *Server, expect *structs.CARoot) {
retry.Run(t, func(r *retry.R) {
_, root := getCAProviderWithLock(srv)
if root == nil {
r.Fatal("no root")
}
if root.ID != expect.ID {
r.Fatalf("current active root is %s; waiting for %s", root.ID, expect.ID)
}
})
}
func getCAProviderWithLock(s *Server) (ca.Provider, *structs.CARoot) {
return s.caManager.getCAProvider()
}
@ -381,7 +369,6 @@ func TestCAManager_RenewIntermediate_Vault_Primary(t *testing.T) {
t.Log("original SigningKeyID", originalRoot.SigningKeyID)
// Get the original intermediate.
waitForActiveCARoot(t, s1, originalRoot)
provider, _ := getCAProviderWithLock(s1)
intermediatePEM, err := provider.ActiveIntermediate()
require.NoError(err)
@ -523,8 +510,8 @@ func TestCAManager_RenewIntermediate_Secondary(t *testing.T) {
}
t.Log("original SigningKeyID", originalRoot.SigningKeyID)
waitForActiveCARoot(t, s1, originalRoot)
waitForActiveCARoot(t, s2, originalRoot)
testrpc.WaitForActiveCARoot(t, s1.RPC, "dc1", originalRoot)
testrpc.WaitForActiveCARoot(t, s2.RPC, "dc2", originalRoot)
store := s2.fsm.State()
_, activeRoot, err := store.CARootActive(nil)

View File

@ -3,9 +3,10 @@ package testrpc
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/sdk/testutil/retry"
"github.com/stretchr/testify/require"
)
type rpcFn func(string, interface{}, interface{}) error
@ -152,13 +153,7 @@ func WaitForActiveCARoot(t *testing.T, rpc rpcFn, dc string, expect *structs.CAR
r.Fatalf("err: %v", err)
}
var root *structs.CARoot
for _, r := range reply.Roots {
if r.ID == reply.ActiveRootID {
root = r
break
}
}
root := reply.Active()
if root == nil {
r.Fatal("no active root")
}