external_tests: ensure derived cores are stable before proceeding on tests (#8342)

* external_tests: ensure derived cores are stable before proceeding on tests

* testhelpers: add min duration tolerance when checking stability on derived core
This commit is contained in:
Calvin Leung Huang 2020-02-13 13:18:53 -08:00 committed by GitHub
parent 8369775247
commit dac3382e15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 3 deletions

View File

@ -186,7 +186,16 @@ func AttemptUnsealCore(c *vault.TestCluster, core *vault.TestClusterCore) error
}
func EnsureStableActiveNode(t testing.T, cluster *vault.TestCluster) {
deriveStableActiveCore(t, cluster)
}
func DeriveStableActiveCore(t testing.T, cluster *vault.TestCluster) *vault.TestClusterCore {
return deriveStableActiveCore(t, cluster)
}
func deriveStableActiveCore(t testing.T, cluster *vault.TestCluster) *vault.TestClusterCore {
activeCore := DeriveActiveCore(t, cluster)
minDuration := time.NewTimer(3 * time.Second)
for i := 0; i < 30; i++ {
leaderResp, err := activeCore.Client.Sys().Leader()
@ -194,10 +203,22 @@ func EnsureStableActiveNode(t testing.T, cluster *vault.TestCluster) {
t.Fatal(err)
}
if !leaderResp.IsSelf {
t.Fatal("unstable active node")
minDuration.Reset(3 * time.Second)
}
time.Sleep(200 * time.Millisecond)
}
select {
case <-minDuration.C:
default:
if stopped := minDuration.Stop(); stopped {
t.Fatal("unstable active node")
}
// Drain the value
<-minDuration.C
}
return activeCore
}
func DeriveActiveCore(t testing.T, cluster *vault.TestCluster) *vault.TestClusterCore {

View File

@ -504,7 +504,7 @@ func TestRaft_SnapshotAPI_RekeyRotate_Backward(t *testing.T) {
cluster.BarrierKeys = barrierKeys
testhelpers.EnsureCoresUnsealed(t, cluster)
testhelpers.WaitForActiveNode(t, cluster)
activeCore := testhelpers.DeriveActiveCore(t, cluster)
activeCore := testhelpers.DeriveStableActiveCore(t, cluster)
// Read the value.
data, err := activeCore.Client.Logical().Read("secret/foo")
@ -707,7 +707,7 @@ func TestRaft_SnapshotAPI_RekeyRotate_Forward(t *testing.T) {
cluster.BarrierKeys = newBarrierKeys
testhelpers.EnsureCoresUnsealed(t, cluster)
testhelpers.WaitForActiveNode(t, cluster)
activeCore := testhelpers.DeriveActiveCore(t, cluster)
activeCore := testhelpers.DeriveStableActiveCore(t, cluster)
// Read the value.
data, err := activeCore.Client.Logical().Read("secret/foo")