Allow ensuring ticker is stopped multiple times (#20509)

When executing multi-stage, multi-namespace tests, stopping the ticker
multiple times (via closing the StopTicker channel) results in a panic.

Store whether or not we've stopped it once, and do not close it again.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
This commit is contained in:
Alexander Scheel 2023-05-04 10:14:06 -04:00 committed by GitHub
parent c1bc341b88
commit 544ae3461f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 7 deletions

View File

@ -43,12 +43,13 @@ type RollbackManager struct {
inflight map[string]*rollbackState
inflightLock sync.RWMutex
doneCh chan struct{}
shutdown bool
shutdownCh chan struct{}
shutdownLock sync.Mutex
stopTicker chan struct{}
quitContext context.Context
doneCh chan struct{}
shutdown bool
shutdownCh chan struct{}
shutdownLock sync.Mutex
stopTicker chan struct{}
tickerIsStopped bool
quitContext context.Context
core *Core
}
@ -103,7 +104,10 @@ func (m *RollbackManager) Stop() {
//
// THIS SHOULD ONLY BE CALLED FROM TEST HELPERS.
func (m *RollbackManager) StopTicker() {
close(m.stopTicker)
if !m.tickerIsStopped {
close(m.stopTicker)
m.tickerIsStopped = true
}
}
// run is a long running routine to periodically invoke rollback