From 70bada6ec44047f5733a56bb9893f437c32a9215 Mon Sep 17 00:00:00 2001 From: Calvin Leung Huang Date: Thu, 5 Sep 2019 13:26:46 -0700 Subject: [PATCH] add and use TestWaitStandby to ensure core is on standby --- http/sys_hostinfo_test.go | 8 +------- vault/testing.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/http/sys_hostinfo_test.go b/http/sys_hostinfo_test.go index 1fe0497bf1d5..0a37c7c8f0c0 100644 --- a/http/sys_hostinfo_test.go +++ b/http/sys_hostinfo_test.go @@ -53,13 +53,7 @@ func TestSysHostInfo(t *testing.T) { } // Check we're standby - healthResp, err := cores[1].Client.Sys().Health() - if err != nil { - t.Fatal(err) - } - if !healthResp.Standby { - t.Fatal("expected node to be standby") - } + vault.TestWaitStandby(t, cores[1].Core) // Query against a standby, should error secret, err = cores[1].Client.Logical().Read("sys/host-info") diff --git a/vault/testing.go b/vault/testing.go index 4a6c061f385b..97063b2b4a5a 100644 --- a/vault/testing.go +++ b/vault/testing.go @@ -783,6 +783,25 @@ func TestWaitActiveWithError(core *Core) error { return nil } +func TestWaitStandby(t testing.T, core *Core) { + t.Helper() + start := time.Now() + var standby bool + var err error + for time.Now().Sub(start) < 30*time.Second { + standby, err = core.Standby() + if standby { + break + } + } + if err != nil { + t.Fatal(err) + } + if !standby { + t.Fatal("should be in standby mode") + } +} + type TestCluster struct { BarrierKeys [][]byte RecoveryKeys [][]byte