Skip to content

test(node): Fix flaky postgresjs integration test - #20351

Closed
JPeer264 wants to merge 1 commit into
developfrom
jp/node-integration-flake
Closed

test(node): Fix flaky postgresjs integration test#20351
JPeer264 wants to merge 1 commit into
developfrom
jp/node-integration-flake

Conversation

@JPeer264

@JPeer264JPeer264 commented Apr 16, 2026

Copy link
Copy Markdown
Member

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.html

Hope this fixes it. Addition from Claude:

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.

@JPeer264JPeer264 self-assigned this Apr 16, 2026
@JPeer264JPeer264 changed the title fix(node): Fix flaky postgresjs integration testtest(node): Fix flaky postgresjs integration testApr 16, 2026
@JPeer264
JPeer264force-pushed the jp/node-integration-flake branch from f9fbd1d to 96ef6a3CompareApril 16, 2026 13:25
Comment threaddev-packages/node-integration-tests/suites/tracing/postgresjs/test.ts Outdated
@github-actions

github-actionsBot commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize% ChangeChange
@sentry/browser25.96 kB--
@sentry/browser - with treeshaking flags24.44 kB--
@sentry/browser (incl. Tracing)43.89 kB--
@sentry/browser (incl. Tracing + Span Streaming)45.53 kB--
@sentry/browser (incl. Tracing, Profiling)48.84 kB--
@sentry/browser (incl. Tracing, Replay)83.09 kB--
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags72.59 kB--
@sentry/browser (incl. Tracing, Replay with Canvas)87.77 kB--
@sentry/browser (incl. Tracing, Replay, Feedback)100.03 kB--
@sentry/browser (incl. Feedback)42.78 kB--
@sentry/browser (incl. sendFeedback)30.64 kB--
@sentry/browser (incl. FeedbackAsync)35.64 kB--
@sentry/browser (incl. Metrics)27.25 kB--
@sentry/browser (incl. Logs)27.38 kB--
@sentry/browser (incl. Metrics & Logs)28.07 kB--
@sentry/react27.72 kB--
@sentry/react (incl. Tracing)46.13 kB--
@sentry/vue30.81 kB--
@sentry/vue (incl. Tracing)45.71 kB--
@sentry/svelte25.98 kB--
CDN Bundle28.66 kB--
CDN Bundle (incl. Tracing)46.12 kB--
CDN Bundle (incl. Logs, Metrics)30.03 kB--
CDN Bundle (incl. Tracing, Logs, Metrics)47.17 kB--
CDN Bundle (incl. Replay, Logs, Metrics)68.99 kB--
CDN Bundle (incl. Tracing, Replay)83.19 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics)84.22 kB--
CDN Bundle (incl. Tracing, Replay, Feedback)88.67 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics)89.75 kB--
CDN Bundle - uncompressed83.91 kB--
CDN Bundle (incl. Tracing) - uncompressed137.82 kB--
CDN Bundle (incl. Logs, Metrics) - uncompressed88.06 kB--
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed141.23 kB--
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed211.63 kB--
CDN Bundle (incl. Tracing, Replay) - uncompressed255.26 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed258.66 kB--
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed268.17 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed271.56 kB--
@sentry/nextjs (client)48.66 kB--
@sentry/sveltekit (client)44.33 kB--
@sentry/node-core58.37 kB+0.02%+8 B 🔺
@sentry/node175.69 kB+0.01%+14 B 🔺
@sentry/node - without tracing98.32 kB+0.02%+14 B 🔺
@sentry/aws-serverless115.35 kB+0.01%+11 B 🔺

View base workflow run

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>
@JPeer264
JPeer264force-pushed the jp/node-integration-flake branch from fd55ebc to 9bbdd3cCompareApril 24, 2026 09:01
@JPeer264

Copy link
Copy Markdown
MemberAuthor

closed in favor of #20429

Comment on lines +221 to +224
.withDockerCompose({
workingDirectory: [__dirname],
readyMatches: ['postgresjs-ready'],
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The readyMatches parameter is passed to a test runner that does not support it. The parameter is silently ignored, making the code misleading and ineffective.
Severity: LOW

Suggested Fix

Remove the readyMatches: ['postgresjs-ready'] parameter from the startDocker call in the test file. The container readiness is already correctly handled by the docker-compose.yml healthcheck and the --wait flag used by the runner.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location:
dev-packages/node-integration-tests/suites/tracing/postgresjs/test.ts#L221-L224
Potential issue: The test configuration passes a `readyMatches` parameter to the
`node-integration-tests` runner. However, the runner's `DockerOptions` interface does
not define or use this property, causing the parameter to be silently ignored at
runtime. This makes the code misleading as it appears to configure a readiness check
that is not actually performed. The test's stability relies solely on the `docker
compose up --wait` command and the service's healthcheck, not this parameter.

Did we get this right? 👍 / 👎 to inform future reviews.

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9bbdd3c. Configure here.

.withDockerCompose({
workingDirectory: [__dirname],
readyMatches: ['postgresjs-ready'],
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readyMatches not supported by this test runner

High Severity

The readyMatches option is passed to withDockerCompose but the DockerOptions interface in the node-integration-tests runner (dev-packages/node-integration-tests/utils/runner.ts) does not include a readyMatches property — it only supports workingDirectory and setupCommand. This feature only exists in the node-core-integration-tests runner. The runner uses docker compose up -d --wait and never reads container logs for match strings, so the entire ready-gate + readyMatches pattern has no effect here and the PR's stated fix (waiting for postgresjs-ready) is not actually achieved.

Additional Locations (1)
Fix in CursorFix in Web

Reviewed by Cursor Bugbot for commit 9bbdd3c. Configure here.

depends_on:
db:
condition: service_healthy
command: ['echo', 'postgresjs-ready']

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ready-gate service missing required Docker healthcheck

High Severity

The new ready-gate service does not define a healthcheck:. The node-integration-tests runner uses docker compose up -d --wait, which relies on healthchecks to know when services are ready. Since ready-gate runs echo and exits immediately, it will be in an "exited" state when --wait checks it, potentially causing the command to fail and throwing an error in the runner.

Fix in CursorFix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 9bbdd3c. Configure here.

Sign up for freeto 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.

3 participants

@JPeer264@nicohrubec@s1gr1d