Skip to content

Commit 8fb70d9

Browse files
committed
fix: context passing
1 parent e170c1d commit 8fb70d9

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

tests/alloydbpg/alloydb_pg_mcp_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func getAlloyDBDialOpts(ipType string) ([]alloydbconn.DialOption, error) {
8383
}
8484
}
8585

86-
func initAlloyDBPgConnectionPool(project, region, cluster, instance, ipType, user, pass, dbname string) (*pgxpool.Pool, error) {
86+
func initAlloyDBPgConnectionPool(ctx context.Context, project, region, cluster, instance, ipType, user, pass, dbname string) (*pgxpool.Pool, error) {
8787
dsn := fmt.Sprintf("user=%s password=%s dbname=%s sslmode=disable", user, pass, dbname)
8888
config, err := pgxpool.ParseConfig(dsn)
8989
if err != nil {
@@ -94,7 +94,7 @@ func initAlloyDBPgConnectionPool(project, region, cluster, instance, ipType, use
9494
if err != nil {
9595
return nil, err
9696
}
97-
d, err := alloydbconn.NewDialer(context.Background(), alloydbconn.WithDefaultDialOptions(dialOpts...))
97+
d, err := alloydbconn.NewDialer(ctx, alloydbconn.WithDefaultDialOptions(dialOpts...))
9898
if err != nil {
9999
return nil, fmt.Errorf("unable to parse connection uri: %w", err)
100100
}
@@ -104,7 +104,7 @@ func initAlloyDBPgConnectionPool(project, region, cluster, instance, ipType, use
104104
return d.Dial(ctx, i)
105105
}
106106

107-
pool, err := pgxpool.NewWithConfig(context.Background(), config)
107+
pool, err := pgxpool.NewWithConfig(ctx, config)
108108
if err != nil {
109109
return nil, err
110110
}
@@ -148,7 +148,7 @@ func TestAlloyDBPgCallTool(t *testing.T) {
148148
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
149149
defer cancel()
150150

151-
pool, err := initAlloyDBPgConnectionPool(AlloyDBPostgresProject, AlloyDBPostgresRegion, AlloyDBPostgresCluster, AlloyDBPostgresInstance, "public", AlloyDBPostgresUser, AlloyDBPostgresPass, AlloyDBPostgresDatabase)
151+
pool, err := initAlloyDBPgConnectionPool(ctx, AlloyDBPostgresProject, AlloyDBPostgresRegion, AlloyDBPostgresCluster, AlloyDBPostgresInstance, "public", AlloyDBPostgresUser, AlloyDBPostgresPass, AlloyDBPostgresDatabase)
152152
if err != nil {
153153
t.Fatalf("unable to create AlloyDB connection pool: %s", err)
154154
}

tests/cloudsqlpg/cloud_sql_pg_mcp_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func getCloudSQLPgVars(t *testing.T) map[string]any {
6969
}
7070
}
7171

72-
func initCloudSQLPgConnectionPool(project, region, instance, ip_type, user, pass, dbname string) (*pgxpool.Pool, error) {
72+
func initCloudSQLPgConnectionPool(ctx context.Context, project, region, instance, ip_type, user, pass, dbname string) (*pgxpool.Pool, error) {
7373
dsn := fmt.Sprintf("user=%s password=%s dbname=%s sslmode=disable", user, pass, dbname)
7474
config, err := pgxpool.ParseConfig(dsn)
7575
if err != nil {
@@ -81,7 +81,7 @@ func initCloudSQLPgConnectionPool(project, region, instance, ip_type, user, pass
8181
if err != nil {
8282
return nil, err
8383
}
84-
d, err := cloudsqlconn.NewDialer(context.Background(), cloudsqlconn.WithDefaultDialOptions(dialOpts...))
84+
d, err := cloudsqlconn.NewDialer(ctx, cloudsqlconn.WithDefaultDialOptions(dialOpts...))
8585
if err != nil {
8686
return nil, fmt.Errorf("unable to parse connection uri: %w", err)
8787
}
@@ -93,7 +93,7 @@ func initCloudSQLPgConnectionPool(project, region, instance, ip_type, user, pass
9393
}
9494

9595
// Interact with the driver directly as you normally would
96-
pool, err := pgxpool.NewWithConfig(context.Background(), config)
96+
pool, err := pgxpool.NewWithConfig(ctx, config)
9797
if err != nil {
9898
return nil, err
9999
}
@@ -136,7 +136,7 @@ func TestCloudSQLPgCallTool(t *testing.T) {
136136
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
137137
defer cancel()
138138

139-
pool, err := initCloudSQLPgConnectionPool(CloudSQLPostgresProject, CloudSQLPostgresRegion, CloudSQLPostgresInstance, "public", CloudSQLPostgresUser, CloudSQLPostgresPass, CloudSQLPostgresDatabase)
139+
pool, err := initCloudSQLPgConnectionPool(ctx, CloudSQLPostgresProject, CloudSQLPostgresRegion, CloudSQLPostgresInstance, "public", CloudSQLPostgresUser, CloudSQLPostgresPass, CloudSQLPostgresDatabase)
140140
if err != nil {
141141
t.Fatalf("unable to create Cloud SQL connection pool: %s", err)
142142
}

0 commit comments

Comments
 (0)