Skip to content

test: open and close test postgresql pools through a shared helper - #3560

Merged
freeqaz merged 2 commits into
mainfrom
test-dry-1025-pools
Oct 25, 2026
Merged

freeqaz merged 2 commits into
mainfrom
test-dry-1025-pools

Conversation

@freeqaz

@freeqaz freeqaz commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

PostgreSQL tests open a pool and close it in an after hook with the same two lines: const pool = new pg.Pool({...}) and then t.after(() => pool.end()). A survey of tests/ on main found 65 such pairs in 26 files.

pool.end() resolves once the pool's idle clients are removed, before their sessions close. When the test's database is dropped right after (DROP DATABASE ... WITH (FORCE)), the drop can end a session that is still closing. The server's 57P01 then reaches the pool, which has no error listener, and the test fails in its teardown. That is finding 2379, fixed for the revision fixture in #3547. withPool in tests/helpers/postgres-database.mjs already avoids it by waiting for each client's own end. The hand-written after hooks do not.

Change

  • tests/helpers/postgres-database.mjs:
    • withPool's close (end the pool, then wait for each client's end) moves into a private closer(pool). withPool uses it unchanged.
    • New testPool(context, config) returns new pg.Pool(config) and registers closer(pool) with context.after at once, where the old after hook was registered. context is a test context or anything with after (the repository credential resource scope).
  • 19 pairs in 13 files now call testPool, with the same pool configuration. postgres-presets' two-pool hook (Promise.all of two ends) becomes two testPool calls. Imports of pg that became unused are removed.
  • The helper adds no error listener: an idle client error still fails the test as before.
  • Left alone:

Test-only. No product code or assertions change.

Verification

Risks

Low. Teardown now also waits until the pool's sessions have closed, as withPool already does. A pool whose client never closes would hold its after hook, but pool.end() already waits for checked-out clients before it resolves.

@freeqaz
freeqaz requested a review from a team as a code owner October 25, 2026 00:49
@clawsweeper

clawsweeper Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@freeqaz
freeqaz merged commit 0f9f4c0 into main Oct 25, 2026
42 checks passed
@freeqaz
freeqaz deleted the test-dry-1025-pools branch October 25, 2026 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant