diff --git a/vault/activity_log.go b/vault/activity_log.go index a84785b0c..029a16a8b 100644 --- a/vault/activity_log.go +++ b/vault/activity_log.go @@ -732,6 +732,19 @@ func (a *ActivityLog) deleteLogWorker(startTimestamp int64, whenDone chan struct close(whenDone) } +func (a *ActivityLog) WaitForDeletion() { + a.l.Lock() + // May be nil, if never set + doneCh := a.deleteDone + a.l.Unlock() + if doneCh != nil { + select { + case <-doneCh: + break + } + } +} + // refreshFromStoredLog loads the appropriate entities/tokencounts for active and performance standbys // the most recent segment is loaded synchronously, and older segments are loaded in the background // this function expects stateLock to be held diff --git a/vault/activity_log_test.go b/vault/activity_log_test.go index dcf231d55..59823d74c 100644 --- a/vault/activity_log_test.go +++ b/vault/activity_log_test.go @@ -1238,6 +1238,13 @@ func TestActivityLog_StopAndRestart(t *testing.T) { DefaultReportMonths: 12, }) + // On enterprise, a segment will be created, and + // disabling it will trigger deletion, so wait + // for that deletion to finish. + // (Alternatively, we could ensure that the next segment + // uses a different timestamp by waiting 1 second.) + a.WaitForDeletion() + // Go through request to ensure config is persisted req := logical.TestRequest(t, logical.UpdateOperation, "internal/counters/config") req.Storage = sysView