Skip to content

Commit 13c1b7c

Browse files
authored
Merge pull request #1198 from GustavoStingelin/sqldb/refactor-test-testing-the-name
wallet: refactor itest testing his name
2 parents 6b51893 + 538178c commit 13c1b7c

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

wallet/internal/db/itest/account_store_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,9 @@ func TestRenameAccount(t *testing.T) {
610610
func TestRenameAccountErrors(t *testing.T) {
611611
t.Parallel()
612612

613+
accountNumber := uint32(99999)
614+
accountPointer := &accountNumber
615+
613616
tests := []struct {
614617
name string
615618
params db.RenameAccountParams
@@ -627,9 +630,10 @@ func TestRenameAccountErrors(t *testing.T) {
627630
{
628631
name: "invalid - both set",
629632
params: db.RenameAccountParams{
630-
Scope: db.KeyScopeBIP0084,
631-
OldName: "nonexistent",
632-
NewName: "new-name",
633+
Scope: db.KeyScopeBIP0084,
634+
OldName: "nonexistent",
635+
AccountNumber: accountPointer,
636+
NewName: "new-name",
633637
},
634638
wantErr: db.ErrInvalidAccountQuery,
635639
},
@@ -661,11 +665,6 @@ func TestRenameAccountErrors(t *testing.T) {
661665
createAllAccounts(t, store, walletID)
662666
tc.params.WalletID = walletID
663667

664-
if tc.name == "invalid - both set" {
665-
num := uint32(99999)
666-
tc.params.AccountNumber = &num
667-
}
668-
669668
err := store.RenameAccount(t.Context(), tc.params)
670669
require.ErrorIs(t, err, tc.wantErr)
671670
})

wallet/internal/db/itest/pg_test.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,33 @@ func GetPostgresContainer(ctx context.Context) (*postgres.PostgresContainer,
132132
},
133133
).WithStartupTimeout(pgInitTimeout)
134134

135+
p := testParallelism()
136+
m := db.DefaultMaxConnections
137+
138+
// pgMaxConns is the Postgres max_connections budget for the
139+
// test container. It is sized as P*M + M + 3*P where:
140+
//
141+
// P*M — steady-state: up to P parallel tests each holding a
142+
// pool of at most M connections (db.SetMaxOpenConns).
143+
//
144+
// +M — teardown latency: one extra store-equivalent for a
145+
// store that has called Close() but whose connections
146+
// have not yet fully disappeared from Postgres.
147+
//
148+
// +3*P — per-slot bootstrap overlap: each slot needs roughly
149+
// 3 transient connections while a new test starts —
150+
// one admin connection for CREATE DATABASE, ~1 for
151+
// PingContext, and ~1 for migration setup — so 3*P
152+
// covers all slots transitioning simultaneously.
153+
pgMaxConns := p*m + m + 3*p
154+
135155
pgContainer, pgContainerErr = postgres.Run(ctx,
136156
cfg.Image,
137157
postgres.WithDatabase(cfg.Database),
138158
postgres.WithUsername(cfg.Username),
139159
postgres.WithPassword(cfg.Password),
140160
testcontainers.WithCmd(
141-
"-c", fmt.Sprintf(
142-
"max_connections=%d",
143-
testParallelism()*db.DefaultMaxConnections,
144-
),
161+
"-c", fmt.Sprintf("max_connections=%d", pgMaxConns),
145162
),
146163
testcontainers.WithWaitStrategyAndDeadline(
147164
pgInitTimeout, waitForSQL,

0 commit comments

Comments
 (0)