MCPcopy
hub / github.com/benbjohnson/litestream / TestStore_ValidationMonitor

Function TestStore_ValidationMonitor

store_test.go:395–440  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

393}
394
395func TestStore_ValidationMonitor(t *testing.T) {
396 t.Run("RunsPeriodically", func(t *testing.T) {
397 db, sqldb := testingutil.MustOpenDBs(t)
398 defer testingutil.MustCloseDBs(t, db, sqldb)
399
400 levels := litestream.CompactionLevels{
401 {Level: 0},
402 {Level: 1, Interval: time.Hour},
403 }
404 store := litestream.NewStore([]*litestream.DB{db}, levels)
405 store.CompactionMonitorEnabled = false
406 store.ValidationInterval = 50 * time.Millisecond
407
408 if err := store.Open(t.Context()); err != nil {
409 t.Fatal(err)
410 }
411
412 // Wait for at least one validation cycle
413 time.Sleep(100 * time.Millisecond)
414
415 if err := store.Close(t.Context()); err != nil {
416 t.Fatal(err)
417 }
418 })
419
420 t.Run("DisabledByDefault", func(t *testing.T) {
421 levels := litestream.CompactionLevels{
422 {Level: 0},
423 }
424 store := litestream.NewStore(nil, levels)
425 store.CompactionMonitorEnabled = false
426
427 // ValidationInterval should be zero by default
428 if store.ValidationInterval != 0 {
429 t.Errorf("expected ValidationInterval=0, got %v", store.ValidationInterval)
430 }
431
432 // Open should succeed without starting validation monitor
433 if err := store.Open(t.Context()); err != nil {
434 t.Fatal(err)
435 }
436 if err := store.Close(t.Context()); err != nil {
437 t.Fatal(err)
438 }
439 })
440}
441
442func TestStore_SetRetentionEnabled(t *testing.T) {
443 db0, sqldb0 := testingutil.MustOpenDBs(t)

Callers

nothing calls this directly

Calls 6

OpenMethod · 0.95
CloseMethod · 0.95
MustOpenDBsFunction · 0.92
MustCloseDBsFunction · 0.92
NewStoreFunction · 0.92
RunMethod · 0.45

Tested by

no test coverage detected