Make manualStepDownCh a 1-buffered channel to ensure StepDown actually steps down in tests. (#9622)

This commit is contained in:
ncabatoff 2020-07-31 10:01:51 -04:00 committed by GitHub
parent fbe2a86693
commit b6fd378ee8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View file

@ -1494,7 +1494,7 @@ func (c *Core) unsealInternal(ctx context.Context, masterKey []byte) (bool, erro
} else { } else {
// Go to standby mode, wait until we are active to unseal // Go to standby mode, wait until we are active to unseal
c.standbyDoneCh = make(chan struct{}) c.standbyDoneCh = make(chan struct{})
c.manualStepDownCh = make(chan struct{}) c.manualStepDownCh = make(chan struct{}, 1)
c.standbyStopCh.Store(make(chan struct{})) c.standbyStopCh.Store(make(chan struct{}))
go c.runStandby(c.standbyDoneCh, c.manualStepDownCh, c.standbyStopCh.Load().(chan struct{})) go c.runStandby(c.standbyDoneCh, c.manualStepDownCh, c.standbyStopCh.Load().(chan struct{}))
} }

View file

@ -1250,7 +1250,7 @@ func TestCore_Standby_Seal(t *testing.T) {
func TestCore_StepDown(t *testing.T) { func TestCore_StepDown(t *testing.T) {
// Create the first core and initialize it // Create the first core and initialize it
logger = logging.NewVaultLogger(log.Trace) logger = logging.NewVaultLogger(log.Trace).Named(t.Name())
inm, err := inmem.NewInmemHA(nil, logger) inm, err := inmem.NewInmemHA(nil, logger)
if err != nil { if err != nil {
@ -1267,6 +1267,7 @@ func TestCore_StepDown(t *testing.T) {
HAPhysical: inmha.(physical.HABackend), HAPhysical: inmha.(physical.HABackend),
RedirectAddr: redirectOriginal, RedirectAddr: redirectOriginal,
DisableMlock: true, DisableMlock: true,
Logger: logger.Named("core1"),
}) })
if err != nil { if err != nil {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
@ -1305,6 +1306,7 @@ func TestCore_StepDown(t *testing.T) {
HAPhysical: inmha.(physical.HABackend), HAPhysical: inmha.(physical.HABackend),
RedirectAddr: redirectOriginal2, RedirectAddr: redirectOriginal2,
DisableMlock: true, DisableMlock: true,
Logger: logger.Named("core2"),
}) })
if err != nil { if err != nil {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)