Skip to content

Commit 2891d76

Browse files
fix: lint and test
1 parent 1561619 commit 2891d76

3 files changed

Lines changed: 32 additions & 14 deletions

File tree

flow/e2e/pg_schema_dump_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,13 @@ func (s PeerFlowE2ETestSuitePG) Test_PG_Schema_Dump_And_CDC() {
220220
EnvWaitFor(s.t, env, 3*time.Minute, "initial load parent", func() bool {
221221
var count int64
222222
err := dstConn.QueryRow(s.t.Context(),
223-
"SELECT COUNT(*) FROM " + dstParent).Scan(&count)
223+
"SELECT COUNT(*) FROM "+dstParent).Scan(&count)
224224
return err == nil && count == 5
225225
})
226226
EnvWaitFor(s.t, env, 3*time.Minute, "initial load child", func() bool {
227227
var count int64
228228
err := dstConn.QueryRow(s.t.Context(),
229-
"SELECT COUNT(*) FROM " + dstChild).Scan(&count)
229+
"SELECT COUNT(*) FROM "+dstChild).Scan(&count)
230230
return err == nil && count == 10
231231
})
232232

@@ -306,29 +306,29 @@ func (s PeerFlowE2ETestSuitePG) Test_PG_Schema_Dump_And_CDC() {
306306
EnvWaitFor(s.t, env, 3*time.Minute, "cdc parent rows", func() bool {
307307
var count int64
308308
err := dstConn.QueryRow(s.t.Context(),
309-
"SELECT COUNT(*) FROM " + dstParent).Scan(&count)
309+
"SELECT COUNT(*) FROM "+dstParent).Scan(&count)
310310
return err == nil && count == 8
311311
})
312312
EnvWaitFor(s.t, env, 3*time.Minute, "cdc child rows", func() bool {
313313
var count int64
314314
err := dstConn.QueryRow(s.t.Context(),
315-
"SELECT COUNT(*) FROM " + dstChild).Scan(&count)
315+
"SELECT COUNT(*) FROM "+dstChild).Scan(&count)
316316
return err == nil && count == 15
317317
})
318318

319319
// verify data integrity: compare actual row content
320320
// query source and destination and compare
321321
var srcParentCount, dstParentCount int64
322-
err = srcConn.QueryRow(s.t.Context(), "SELECT COUNT(*) FROM " + srcParent).Scan(&srcParentCount)
322+
err = srcConn.QueryRow(s.t.Context(), "SELECT COUNT(*) FROM "+srcParent).Scan(&srcParentCount)
323323
require.NoError(s.t, err)
324-
err = dstConn.QueryRow(s.t.Context(), "SELECT COUNT(*) FROM " + dstParent).Scan(&dstParentCount)
324+
err = dstConn.QueryRow(s.t.Context(), "SELECT COUNT(*) FROM "+dstParent).Scan(&dstParentCount)
325325
require.NoError(s.t, err)
326326
require.Equal(s.t, srcParentCount, dstParentCount, "parent table row counts should match")
327327

328328
var srcChildCount, dstChildCount int64
329-
err = srcConn.QueryRow(s.t.Context(), "SELECT COUNT(*) FROM " + srcChild).Scan(&srcChildCount)
329+
err = srcConn.QueryRow(s.t.Context(), "SELECT COUNT(*) FROM "+srcChild).Scan(&srcChildCount)
330330
require.NoError(s.t, err)
331-
err = dstConn.QueryRow(s.t.Context(), "SELECT COUNT(*) FROM " + dstChild).Scan(&dstChildCount)
331+
err = dstConn.QueryRow(s.t.Context(), "SELECT COUNT(*) FROM "+dstChild).Scan(&dstChildCount)
332332
require.NoError(s.t, err)
333333
require.Equal(s.t, srcChildCount, dstChildCount, "child table row counts should match")
334334

@@ -437,7 +437,7 @@ func (s PeerFlowE2ETestSuitePG) Test_PG_Schema_Dump_No_Owner_No_Privileges() {
437437
EnvWaitFor(s.t, env, 3*time.Minute, "initial load owned_tbl", func() bool {
438438
var count int64
439439
err := dstConn.QueryRow(s.t.Context(),
440-
"SELECT COUNT(*) FROM " + qualified).Scan(&count)
440+
"SELECT COUNT(*) FROM "+qualified).Scan(&count)
441441
return err == nil && count == 5
442442
})
443443

@@ -452,7 +452,7 @@ func (s PeerFlowE2ETestSuitePG) Test_PG_Schema_Dump_No_Owner_No_Privileges() {
452452
EnvWaitFor(s.t, env, 3*time.Minute, "cdc owned_tbl", func() bool {
453453
var count int64
454454
err := dstConn.QueryRow(s.t.Context(),
455-
"SELECT COUNT(*) FROM " + qualified).Scan(&count)
455+
"SELECT COUNT(*) FROM "+qualified).Scan(&count)
456456
return err == nil && count == 10
457457
})
458458

flow/e2e/test_utils.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import (
88
"log/slog"
99
"slices"
1010
"strings"
11+
"sync"
1112
"testing"
1213
"time"
1314

1415
"github.com/google/uuid"
1516
"github.com/jackc/pgerrcode"
1617
"github.com/jackc/pgx/v5"
18+
"github.com/jackc/pgx/v5/pgxpool"
1719
"github.com/stretchr/testify/require"
1820
"go.temporal.io/api/enums/v1"
1921
"go.temporal.io/sdk/client"
@@ -724,11 +726,26 @@ func (env WorkflowRun) Query(ctx context.Context, queryType string, args ...any)
724726
return env.c.QueryWorkflow(ctx, env.GetID(), "", queryType, args...)
725727
}
726728

729+
// catalogTestAccessPool is a pgxpool with application_name="catalog_test_access"
730+
// so test-side catalog reads are not collateral damage when other tests issue
731+
// pg_terminate_backend WHERE application_name='peerdb' (see api_test.go).
732+
var catalogTestAccessPool = sync.OnceValues(func() (*pgxpool.Pool, error) {
733+
ctx := context.Background()
734+
connStr := internal.GetCatalogConnectionStringFromEnv(ctx)
735+
cfg, err := pgxpool.ParseConfig(connStr)
736+
if err != nil {
737+
return nil, err
738+
}
739+
cfg.ConnConfig.RuntimeParams["application_name"] = "catalog_test_access"
740+
cfg.MaxConns = 3
741+
return pgxpool.NewWithConfig(ctx, cfg)
742+
})
743+
727744
func (env WorkflowRun) GetFlowStatus(t *testing.T) protos.FlowStatus {
728745
t.Helper()
729-
pool, err := internal.GetCatalogConnectionPoolFromEnv(t.Context())
746+
pool, err := catalogTestAccessPool()
730747
EnvNoError(t, env, err)
731-
status, err := internal.GetWorkflowStatus(t.Context(), pool, env.GetID())
748+
status, err := internal.GetWorkflowStatus(t.Context(), shared.CatalogPool{Pool: pool}, env.GetID())
732749
EnvNoError(t, env, err)
733750
return status
734751
}

flow/internal/dynamicconf.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,9 @@ var DynamicSettings = [...]*protos.DynamicSetting{
445445
TargetForSetting: protos.DynconfTarget_ALL,
446446
},
447447
{
448-
Name: "PEERDB_PG_AUTOMATED_SCHEMA_DUMP",
449-
Description: "For PG-to-PG mirrors, run pg_dump --schema-only from source into psql on destination during setup so destination schema/tables/indexes match the source.",
448+
Name: "PEERDB_PG_AUTOMATED_SCHEMA_DUMP",
449+
Description: "For PG-to-PG mirrors, run pg_dump --schema-only from source into psql on destination " +
450+
"during setup so destination schema/tables/indexes match the source.",
450451
DefaultValue: "false",
451452
ValueType: protos.DynconfValueType_BOOL,
452453
ApplyMode: protos.DynconfApplyMode_APPLY_MODE_AFTER_RESUME,

0 commit comments

Comments
 (0)