fix(store): harden background purge interval

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-03 07:35:20 +00:00
parent acad59664d
commit 841e7b8936
2 changed files with 16 additions and 1 deletions

View file

@ -656,9 +656,13 @@ func (storeInstance *Store) startBackgroundPurge() {
if storeInstance.purgeContext == nil {
return
}
if storeInstance.purgeInterval <= 0 {
storeInstance.purgeInterval = 60 * time.Second
}
purgeInterval := storeInstance.purgeInterval
storeInstance.purgeWaitGroup.Go(func() {
ticker := time.NewTicker(storeInstance.purgeInterval)
ticker := time.NewTicker(purgeInterval)
defer ticker.Stop()
for {
select {

View file

@ -1340,6 +1340,17 @@ func TestStore_PurgeExpired_Good_BackgroundPurge(t *testing.T) {
assert.Equal(t, 1, count, "background purge should have deleted the expired row")
}
func TestStore_StartBackgroundPurge_Good_DefaultsWhenIntervalUnset(t *testing.T) {
storeInstance, err := New(":memory:")
require.NoError(t, err)
storeInstance.purgeInterval = 0
require.NotPanics(t, func() {
storeInstance.startBackgroundPurge()
})
require.NoError(t, storeInstance.Close())
}
// ---------------------------------------------------------------------------
// Schema migration — reopening an existing database
// ---------------------------------------------------------------------------