From 9bbdd3c05ef0c7164dc48d280d395e6a0813e755 Mon Sep 17 00:00:00 2001 From: JPeer264 Date: Thu, 16 Apr 2026 15:20:35 +0200 Subject: [PATCH] test(node): Fix flaky postgresjs integration test 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 --- .../tracing/postgresjs/docker-compose.yml | 13 ++++-- .../suites/tracing/postgresjs/test.ts | 40 +++++++++++++++---- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/dev-packages/node-integration-tests/suites/tracing/postgresjs/docker-compose.yml b/dev-packages/node-integration-tests/suites/tracing/postgresjs/docker-compose.yml index f3afd85af9ab..411c58e44de9 100644 --- a/dev-packages/node-integration-tests/suites/tracing/postgresjs/docker-compose.yml +++ b/dev-packages/node-integration-tests/suites/tracing/postgresjs/docker-compose.yml @@ -13,7 +13,14 @@ services: POSTGRES_DB: test_db healthcheck: test: ['CMD-SHELL', 'pg_isready -U test -d test_db'] - interval: 2s + interval: 500ms timeout: 3s - retries: 30 - start_period: 5s + retries: 60 + start_period: 2s + + ready-gate: + image: busybox + depends_on: + db: + condition: service_healthy + command: ['echo', 'postgresjs-ready'] diff --git a/dev-packages/node-integration-tests/suites/tracing/postgresjs/test.ts b/dev-packages/node-integration-tests/suites/tracing/postgresjs/test.ts index f5f06208812e..225c11934eee 100644 --- a/dev-packages/node-integration-tests/suites/tracing/postgresjs/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/postgresjs/test.ts @@ -218,7 +218,10 @@ describe('postgresjs auto instrumentation', () => { }; await createRunner(__dirname, 'scenario.js') - .withDockerCompose({ workingDirectory: [__dirname] }) + .withDockerCompose({ + workingDirectory: [__dirname], + readyMatches: ['postgresjs-ready'], + }) .expect({ transaction: EXPECTED_TRANSACTION }) .expect({ event: EXPECTED_ERROR_EVENT }) .start() @@ -438,7 +441,10 @@ describe('postgresjs auto instrumentation', () => { await createRunner(__dirname, 'scenario.mjs') .withFlags('--import', `${__dirname}/instrument.mjs`) - .withDockerCompose({ workingDirectory: [__dirname] }) + .withDockerCompose({ + workingDirectory: [__dirname], + readyMatches: ['postgresjs-ready'], + }) .expect({ transaction: EXPECTED_TRANSACTION }) .expect({ event: EXPECTED_ERROR_EVENT }) .start() @@ -532,7 +538,10 @@ describe('postgresjs auto instrumentation', () => { await createRunner(__dirname, 'scenario-requestHook.js') .withFlags('--require', `${__dirname}/instrument-requestHook.cjs`) - .withDockerCompose({ workingDirectory: [__dirname] }) + .withDockerCompose({ + workingDirectory: [__dirname], + readyMatches: ['postgresjs-ready'], + }) .expect({ transaction: EXPECTED_TRANSACTION }) .start() .completed(); @@ -625,7 +634,10 @@ describe('postgresjs auto instrumentation', () => { await createRunner(__dirname, 'scenario-requestHook.mjs') .withFlags('--import', `${__dirname}/instrument-requestHook.mjs`) - .withDockerCompose({ workingDirectory: [__dirname] }) + .withDockerCompose({ + workingDirectory: [__dirname], + readyMatches: ['postgresjs-ready'], + }) .expect({ transaction: EXPECTED_TRANSACTION }) .start() .completed(); @@ -706,7 +718,10 @@ describe('postgresjs auto instrumentation', () => { }; await createRunner(__dirname, 'scenario-url.cjs') - .withDockerCompose({ workingDirectory: [__dirname] }) + .withDockerCompose({ + workingDirectory: [__dirname], + readyMatches: ['postgresjs-ready'], + }) .expect({ transaction: EXPECTED_TRANSACTION }) .start() .completed(); @@ -787,7 +802,10 @@ describe('postgresjs auto instrumentation', () => { await createRunner(__dirname, 'scenario-url.mjs') .withFlags('--import', `${__dirname}/instrument.mjs`) - .withDockerCompose({ workingDirectory: [__dirname] }) + .withDockerCompose({ + workingDirectory: [__dirname], + readyMatches: ['postgresjs-ready'], + }) .expect({ transaction: EXPECTED_TRANSACTION }) .start() .completed(); @@ -866,7 +884,10 @@ describe('postgresjs auto instrumentation', () => { }; await createRunner(__dirname, 'scenario-unsafe.cjs') - .withDockerCompose({ workingDirectory: [__dirname] }) + .withDockerCompose({ + workingDirectory: [__dirname], + readyMatches: ['postgresjs-ready'], + }) .expect({ transaction: EXPECTED_TRANSACTION }) .start() .completed(); @@ -946,7 +967,10 @@ describe('postgresjs auto instrumentation', () => { await createRunner(__dirname, 'scenario-unsafe.mjs') .withFlags('--import', `${__dirname}/instrument.mjs`) - .withDockerCompose({ workingDirectory: [__dirname] }) + .withDockerCompose({ + workingDirectory: [__dirname], + readyMatches: ['postgresjs-ready'], + }) .expect({ transaction: EXPECTED_TRANSACTION }) .start() .completed();