refactor(backend): update test files for PoolProxy and per-test transactions
Migrate all test files from SetupTestDB/db.DB pattern to per-test transactions: - Replace SetupTestDB(t) with SetupTestTx(t) for context + transaction - Replace db.DB.Query/QueryRow/Exec with tx.Query/QueryRow/Exec - Replace context.Background() with context from SetupTestTx - Replace defer rows.Close() pattern with explicit rows.Close() - Add testdb.SeedBaseline(pool) to all TestMain functions - Wire db.Conn = db.NewPoolProxy(pool) in all TestMain functions Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
+11
-11
@@ -19,9 +19,9 @@ func resetEnv() {
|
||||
}
|
||||
|
||||
func closePool() {
|
||||
if DB != nil {
|
||||
DB.Close()
|
||||
DB = nil
|
||||
if Conn != nil {
|
||||
Conn.Pool().Close()
|
||||
Conn = nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ func TestConnect_Success(t *testing.T) {
|
||||
}
|
||||
defer closePool()
|
||||
|
||||
if DB == nil {
|
||||
t.Fatal("DB is nil after successful Connect")
|
||||
if Conn == nil {
|
||||
t.Fatal("Conn is nil after successful Connect")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,14 +56,14 @@ func TestConnect_PingViaTestDB(t *testing.T) {
|
||||
}
|
||||
defer closePool()
|
||||
|
||||
conn, err := DB.Acquire(context.Background())
|
||||
poolConn, err := Conn.Acquire(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("Acquire failed: %v", err)
|
||||
}
|
||||
defer conn.Release()
|
||||
defer poolConn.Release()
|
||||
|
||||
var result int
|
||||
err = conn.QueryRow(context.Background(), "SELECT 1").Scan(&result)
|
||||
err = poolConn.QueryRow(context.Background(), "SELECT 1").Scan(&result)
|
||||
if err != nil {
|
||||
t.Fatalf("Ping query failed: %v", err)
|
||||
}
|
||||
@@ -127,15 +127,15 @@ func TestConcurrentQueries(t *testing.T) {
|
||||
wg.Add(1)
|
||||
go func(id int) {
|
||||
defer wg.Done()
|
||||
conn, err := DB.Acquire(context.Background())
|
||||
poolConn, err := Conn.Acquire(context.Background())
|
||||
if err != nil {
|
||||
errs <- fmt.Errorf("goroutine %d: acquire: %w", id, err)
|
||||
return
|
||||
}
|
||||
defer conn.Release()
|
||||
defer poolConn.Release()
|
||||
|
||||
var result int
|
||||
err = conn.QueryRow(context.Background(), "SELECT $1::int", id).Scan(&result)
|
||||
err = poolConn.QueryRow(context.Background(), "SELECT $1::int", id).Scan(&result)
|
||||
if err != nil {
|
||||
errs <- fmt.Errorf("goroutine %d: query: %w", id, err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user