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

Function TestDB_Checkpoint_ErrorMetrics

db_internal_test.go:510–553  ·  view source on GitHub ↗

TestDB_Checkpoint_ErrorMetrics verifies that checkpoint error counter is incremented on failure.

(t *testing.T)

Source from the content-addressed store, hash-verified

508
509// TestDB_Checkpoint_ErrorMetrics verifies that checkpoint error counter is incremented on failure.
510func TestDB_Checkpoint_ErrorMetrics(t *testing.T) {
511 dir := t.TempDir()
512 dbPath := filepath.Join(dir, "db")
513
514 db := NewDB(dbPath)
515 db.MonitorInterval = 0
516 db.Replica = NewReplica(db)
517 db.Replica.Client = &testReplicaClient{dir: t.TempDir()}
518 db.Replica.MonitorEnabled = false
519 if err := db.Open(); err != nil {
520 t.Fatal(err)
521 }
522 defer func() { _ = db.Close(context.Background()) }()
523
524 sqldb, err := sql.Open("sqlite", dbPath)
525 if err != nil {
526 t.Fatal(err)
527 }
528 defer sqldb.Close()
529
530 if _, err := sqldb.Exec(`CREATE TABLE t (id INT, data TEXT)`); err != nil {
531 t.Fatal(err)
532 }
533 if _, err := sqldb.Exec(`INSERT INTO t VALUES (1, 'test data')`); err != nil {
534 t.Fatal(err)
535 }
536
537 if err := db.Sync(context.Background()); err != nil {
538 t.Fatal(err)
539 }
540
541 baselineErrors := testutil.ToFloat64(checkpointErrorNCounterVec.WithLabelValues(db.Path(), "PASSIVE"))
542
543 db.db.Close()
544
545 if err := db.execCheckpoint(context.Background(), "PASSIVE"); err == nil {
546 t.Fatal("expected error from checkpoint with closed db")
547 }
548
549 checkpointErrorValue := testutil.ToFloat64(checkpointErrorNCounterVec.WithLabelValues(db.Path(), "PASSIVE"))
550 if checkpointErrorValue <= baselineErrors {
551 t.Fatalf("litestream_checkpoint_error_count=%v, want > %v", checkpointErrorValue, baselineErrors)
552 }
553}
554
555// TestDB_L0RetentionMetrics verifies that L0 retention gauges are set during enforcement.
556func TestDB_L0RetentionMetrics(t *testing.T) {

Callers

nothing calls this directly

Calls 7

OpenMethod · 0.95
CloseMethod · 0.95
SyncMethod · 0.95
PathMethod · 0.95
execCheckpointMethod · 0.95
NewReplicaFunction · 0.85
NewDBFunction · 0.70

Tested by

no test coverage detected