diff --git a/agent/consul/connect_ca_endpoint_test.go b/agent/consul/connect_ca_endpoint_test.go index d5e52f9e3f..40a384f902 100644 --- a/agent/consul/connect_ca_endpoint_test.go +++ b/agent/consul/connect_ca_endpoint_test.go @@ -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") diff --git a/agent/consul/leader_connect_test.go b/agent/consul/leader_connect_test.go index 9ae5a9aaec..2e7d8b9710 100644 --- a/agent/consul/leader_connect_test.go +++ b/agent/consul/leader_connect_test.go @@ -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) diff --git a/testrpc/wait.go b/testrpc/wait.go index 63f6b603ea..a872668cea 100644 --- a/testrpc/wait.go +++ b/testrpc/wait.go @@ -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") }