TestDB_Checkpoint_ErrorMetrics verifies that checkpoint error counter is incremented on failure.
(t *testing.T)
| 508 | |
| 509 | // TestDB_Checkpoint_ErrorMetrics verifies that checkpoint error counter is incremented on failure. |
| 510 | func 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. |
| 556 | func TestDB_L0RetentionMetrics(t *testing.T) { |
nothing calls this directly
no test coverage detected