This commit is contained in:
@@ -3,6 +3,7 @@ package db
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -32,6 +33,37 @@ func indexExists(t *testing.T, dbConn *sqlx.DB, name string) bool {
|
||||
return count > 0
|
||||
}
|
||||
|
||||
func TestEnsureOncePerDBRetriesUntilSuccess(t *testing.T) {
|
||||
dbConn := newTestSQLiteDB(t)
|
||||
attempts := 0
|
||||
run := func() error {
|
||||
attempts++
|
||||
if attempts == 1 {
|
||||
return errors.New("transient failure")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := ensureOncePerDB(dbConn, "test_once", run); err == nil {
|
||||
t.Fatal("expected first ensureOncePerDB call to fail")
|
||||
}
|
||||
if attempts != 1 {
|
||||
t.Fatalf("expected 1 attempt after first call, got %d", attempts)
|
||||
}
|
||||
if err := ensureOncePerDB(dbConn, "test_once", run); err != nil {
|
||||
t.Fatalf("expected second ensureOncePerDB call to succeed, got %v", err)
|
||||
}
|
||||
if attempts != 2 {
|
||||
t.Fatalf("expected 2 attempts after retry, got %d", attempts)
|
||||
}
|
||||
if err := ensureOncePerDB(dbConn, "test_once", run); err != nil {
|
||||
t.Fatalf("expected third ensureOncePerDB call to reuse success, got %v", err)
|
||||
}
|
||||
if attempts != 2 {
|
||||
t.Fatalf("expected no additional attempts after success, got %d", attempts)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCleanupHourlySnapshotIndexesOlderThan(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
dbConn := newTestSQLiteDB(t)
|
||||
|
||||
Reference in New Issue
Block a user