Fix flaky ActivityLog unit test (#10860)
* Wait for initial retention run to finish before adding segments.
This commit is contained in:
parent
bbfbb87115
commit
c5fd996a36
|
@ -137,6 +137,10 @@ type ActivityLog struct {
|
|||
// channel closed by delete worker when done
|
||||
deleteDone chan struct{}
|
||||
|
||||
// channel closed when deletion at startup is done
|
||||
// (for unit test robustness)
|
||||
retentionDone chan struct{}
|
||||
|
||||
// for testing: is config currently being invalidated. protected by l
|
||||
configInvalidationInProgress bool
|
||||
}
|
||||
|
@ -975,7 +979,12 @@ func (c *Core) setupActivityLog(ctx context.Context, wg *sync.WaitGroup) error {
|
|||
go manager.precomputedQueryWorker()
|
||||
|
||||
// Catch up on garbage collection
|
||||
go manager.retentionWorker(time.Now(), manager.retentionMonths)
|
||||
// Signal when this is done so that unit tests can proceed.
|
||||
manager.retentionDone = make(chan struct{})
|
||||
go func() {
|
||||
manager.retentionWorker(time.Now(), manager.retentionMonths)
|
||||
close(manager.retentionDone)
|
||||
}()
|
||||
}
|
||||
|
||||
// Link the token store to this core
|
||||
|
|
|
@ -2307,11 +2307,26 @@ func TestActivityLog_NextMonthStart(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// The retention worker is called on unseal; wait for it to finish before
|
||||
// proceeding with the test.
|
||||
func waitForRetentionWorkerToFinish(t *testing.T, a *ActivityLog) {
|
||||
t.Helper()
|
||||
timeout := time.After(30 * time.Second)
|
||||
select {
|
||||
case <-a.retentionDone:
|
||||
return
|
||||
case <-timeout:
|
||||
t.Fatal("timeout waiting for retention worker to finish")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestActivityLog_Deletion(t *testing.T) {
|
||||
timeutil.SkipAtEndOfMonth(t)
|
||||
|
||||
core, _, _ := TestCoreUnsealed(t)
|
||||
a := core.activityLog
|
||||
waitForRetentionWorkerToFinish(t, a)
|
||||
|
||||
times := []time.Time{
|
||||
time.Date(2019, 1, 15, 1, 2, 3, 0, time.UTC), // 0
|
||||
|
|
Loading…
Reference in New Issue