From 8b6a07c693ab2517628f1600b56df1c36047bec3 Mon Sep 17 00:00:00 2001 From: nick Date: Thu, 22 Aug 2024 15:02:34 +0900 Subject: [PATCH] fix: rollback db timeout --- node/pkg/db/pgsql.go | 8 +---- node/pkg/db/pgsql_test.go | 63 --------------------------------------- 2 files changed, 1 insertion(+), 70 deletions(-) diff --git a/node/pkg/db/pgsql.go b/node/pkg/db/pgsql.go index 2574f379b..4213f0290 100644 --- a/node/pkg/db/pgsql.go +++ b/node/pkg/db/pgsql.go @@ -6,7 +6,6 @@ import ( "fmt" "strings" "sync" - "time" errorSentinel "bisonai.com/miko/node/pkg/error" "bisonai.com/miko/node/pkg/secrets" @@ -23,8 +22,6 @@ var ( poolErr error ) -const DefaultDBTimeout = 60 * time.Second - func GetPool(ctx context.Context) (*pgxpool.Pool, error) { return getPool(ctx, &initPgxOnce) } @@ -103,10 +100,7 @@ func QueryRows[T any](ctx context.Context, queryString string, args map[string]a } func query(ctx context.Context, pool *pgxpool.Pool, query string, args map[string]any) (pgx.Rows, error) { - ctxWithTimeout, cancel := context.WithTimeout(ctx, DefaultDBTimeout) - defer cancel() - - return pool.Query(ctxWithTimeout, query, pgx.NamedArgs(args)) + return pool.Query(ctx, query, pgx.NamedArgs(args)) } func queryRow[T any](ctx context.Context, pool *pgxpool.Pool, queryString string, args map[string]any) (T, error) { diff --git a/node/pkg/db/pgsql_test.go b/node/pkg/db/pgsql_test.go index 35e4d92ac..84e4e82f0 100644 --- a/node/pkg/db/pgsql_test.go +++ b/node/pkg/db/pgsql_test.go @@ -2,8 +2,6 @@ package db import ( "context" - "errors" - "os" "reflect" "testing" ) @@ -502,64 +500,3 @@ func TestBulkSelect(t *testing.T) { }) } - -func TestQueryTimeout(t *testing.T) { - t.Skip("") - // Setting up the context with a short timeout - ctx := context.Background() - - pool, err := GetPool(ctx) - if err != nil { - t.Fatalf("GetPool failed: %v", err) - } - - // Create a temporary table (optional, depending on your test needs) - _, err = pool.Exec(ctx, `CREATE TEMPORARY TABLE test_timeout (id SERIAL PRIMARY KEY, name TEXT)`) - if err != nil { - t.Fatalf("Failed to create temporary table: %v", err) - } - - // Simulate a long-running query using pg_sleep (2 seconds) - _, err = QueryRow[struct { - Name string `db:"name"` - }](ctx, `SELECT pg_sleep(16)`, nil) - - // Check for context.DeadlineExceeded error - if err == nil { - t.Fatalf("Expected timeout error but got none") - } - if !errors.Is(err, context.DeadlineExceeded) { - t.Fatalf("Expected context.DeadlineExceeded error, but got: %v", err) - } -} - -func TestQueryTimeoutTransient(t *testing.T) { - t.Skip("") - ctx := context.Background() - - dbUrl := os.Getenv("DATABASE_URL") - pool, err := GetTransientPool(ctx, dbUrl) - if err != nil { - t.Fatalf("GetPool failed: %v", err) - } - defer pool.Close() - - // Create a temporary table (optional, depending on your test needs) - _, err = pool.Exec(ctx, `CREATE TEMPORARY TABLE test_timeout (id SERIAL PRIMARY KEY, name TEXT)`) - if err != nil { - t.Fatalf("Failed to create temporary table: %v", err) - } - - // Simulate a long-running query using pg_sleep (2 seconds) - _, err = QueryRow[struct { - Name string `db:"name"` - }](ctx, `SELECT pg_sleep(16)`, nil) - - // Check for context.DeadlineExceeded error - if err == nil { - t.Fatalf("Expected timeout error but got none") - } - if !errors.Is(err, context.DeadlineExceeded) { - t.Fatalf("Expected context.DeadlineExceeded error, but got: %v", err) - } -}