test(node): Fix flaky postgresjs integration test#20351
test(node): Fix flaky postgresjs integration test#20351
Conversation
The test was flaky because it used `readyMatches: ['port 5432']` to detect
when PostgreSQL was ready. However, PostgreSQL logs "port 5432" when it starts
listening, but before it's fully ready to accept connections.
On CI runners under load, the gap between binding to the port and being ready
to serve queries was long enough that tests sometimes received PostgreSQL error
57P03 ("cannot_connect_now") because the database was still initializing.
Changed to wait for "database system is ready to accept connections" which
PostgreSQL logs when it's actually ready to serve queries.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
f9fbd1d to
96ef6a3
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 96ef6a3. Configure here.
|
|
||
| await createRunner(__dirname, 'scenario.js') | ||
| .withDockerCompose({ workingDirectory: [__dirname], readyMatches: ['port 5432'] }) | ||
| .withDockerCompose({ workingDirectory: [__dirname], readyMatches: ['database system is ready to accept connections'] }) |
There was a problem hiding this comment.
Ready match triggers on temporary init server, increasing flakiness
Medium Severity
The PostgreSQL Docker image logs "database system is ready to accept connections" twice on first startup: once for a temporary init server (used to create databases/users) and again for the real server after the temp one shuts down. Since the tests use docker compose down --volumes, every run is a fresh init. The readyMatches handler in runner.ts matches the first occurrence, which fires during the temporary server — before the database is truly ready. The old match 'port 5432' was actually safer since the temp server uses Unix sockets only and doesn't listen on TCP port 5432.
Additional Locations (2)
Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit 96ef6a3. Configure here.
size-limit report 📦
|


While releasing a new SDK version I've seen a flaky integration test: https://github.com/getsentry/sentry-javascript/actions/runs/24508519594/job/71634188547?pr=20348
The error actually showed
"db.response.status_code": "57P03",which means that the DB is not yet ready: https://www.postgresql.org/docs/current/errcodes-appendix.htmlHope this fixes it. Addition from Claude:
The test was flaky because it used
readyMatches: ['port 5432']to detectwhen PostgreSQL was ready. However, PostgreSQL logs "port 5432" when it starts
listening, but before it's fully ready to accept connections.
On CI runners under load, the gap between binding to the port and being ready
to serve queries was long enough that tests sometimes received PostgreSQL error
57P03 ("cannot_connect_now") because the database was still initializing.
Changed to wait for "database system is ready to accept connections" which
PostgreSQL logs when it's actually ready to serve queries.