backport of commit a19322d575 (#20452)

Co-authored-by: Peter Wilson <peter.wilson@hashicorp.com>
This commit is contained in:
hc-github-team-secure-vault-core
2023-05-01 16:06:58 -04:00
committed by GitHub
parent 11b9b2db71
commit 051475a3a8
2 changed files with 31 additions and 31 deletions

View File

@@ -1013,3 +1013,34 @@ func SkipUnlessEnvVarsSet(t testing.T, envVars []string) {
}
}
}
// WaitForNodesExcludingSelectedStandbys is variation on WaitForActiveNodeAndStandbys.
// It waits for the active node before waiting for standby nodes, however
// it will not wait for cores with indexes that match those specified as arguments.
// Whilst you could specify index 0 which is likely to be the leader node, the function
// checks for the leader first regardless of the indexes to skip, so it would be redundant to do so.
// The intention/use case for this function is to allow a cluster to start and become active with one
// or more nodes not joined, so that we can test scenarios where a node joins later.
// e.g. 4 nodes in the cluster, only 3 nodes in cluster 'active', 1 node can be joined later in tests.
func WaitForNodesExcludingSelectedStandbys(t testing.T, cluster *vault.TestCluster, indexesToSkip ...int) {
WaitForActiveNode(t, cluster)
contains := func(elems []int, e int) bool {
for _, v := range elems {
if v == e {
return true
}
}
return false
}
for i, core := range cluster.Cores {
if contains(indexesToSkip, i) {
continue
}
if standby, _ := core.Core.Standby(); standby {
WaitForStandbyNode(t, core)
}
}
}

View File

@@ -17,34 +17,3 @@ func WaitForActiveNodeAndStandbys(t testing.T, cluster *vault.TestCluster) {
}
}
}
// WaitForNodesExcludingSelectedStandbys is variation on WaitForActiveNodeAndStandbys.
// It waits for the active node before waiting for standby nodes, however
// it will not wait for cores with indexes that match those specified as arguments.
// Whilst you could specify index 0 which is likely to be the leader node, the function
// checks for the leader first regardless of the indexes to skip, so it would be redundant to do so.
// The intention/use case for this function is to allow a cluster to start and become active with one
// or more nodes not joined, so that we can test scenarios where a node joins later.
// e.g. 4 nodes in the cluster, only 3 nodes in cluster 'active', 1 node can be joined later in tests.
func WaitForNodesExcludingSelectedStandbys(t testing.T, cluster *vault.TestCluster, indexesToSkip ...int) {
WaitForActiveNode(t, cluster)
contains := func(elems []int, e int) bool {
for _, v := range elems {
if v == e {
return true
}
}
return false
}
for i, core := range cluster.Cores {
if contains(indexesToSkip, i) {
continue
}
if standby, _ := core.Core.Standby(); standby {
WaitForStandbyNode(t, core)
}
}
}