From 311b4d9376ad3bad668272ccef984d1fd001d08f Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Tue, 4 Apr 2023 14:32:01 +0000 Subject: [PATCH] backport of commit a19322d57558a0432430323ba795b14b7943a48e --- helper/testhelpers/testhelpers.go | 31 +++++++++++++++++++++++++++ helper/testhelpers/testhelpers_oss.go | 31 --------------------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/helper/testhelpers/testhelpers.go b/helper/testhelpers/testhelpers.go index 5cb4fc3fe8fb..55a6e9d9b33a 100644 --- a/helper/testhelpers/testhelpers.go +++ b/helper/testhelpers/testhelpers.go @@ -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) + } + } +} diff --git a/helper/testhelpers/testhelpers_oss.go b/helper/testhelpers/testhelpers_oss.go index 5f8241934959..912d50fdec3b 100644 --- a/helper/testhelpers/testhelpers_oss.go +++ b/helper/testhelpers/testhelpers_oss.go @@ -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) - } - } -}