diff --git a/store.go b/store.go index 7fe0505..89905ae 100644 --- a/store.go +++ b/store.go @@ -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 { diff --git a/store_test.go b/store_test.go index 5132321..becbdc9 100644 --- a/store_test.go +++ b/store_test.go @@ -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 // ---------------------------------------------------------------------------