Skip to content

Commit 9bbdd3c

Browse files
JPeer264claude
andcommitted
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 <noreply@anthropic.com>
1 parent e2d35a2 commit 9bbdd3c

2 files changed

Lines changed: 42 additions & 11 deletions

File tree

dev-packages/node-integration-tests/suites/tracing/postgresjs/docker-compose.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@ services:
1313
POSTGRES_DB: test_db
1414
healthcheck:
1515
test: ['CMD-SHELL', 'pg_isready -U test -d test_db']
16-
interval: 2s
16+
interval: 500ms
1717
timeout: 3s
18-
retries: 30
19-
start_period: 5s
18+
retries: 60
19+
start_period: 2s
20+
21+
ready-gate:
22+
image: busybox
23+
depends_on:
24+
db:
25+
condition: service_healthy
26+
command: ['echo', 'postgresjs-ready']

dev-packages/node-integration-tests/suites/tracing/postgresjs/test.ts

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,10 @@ describe('postgresjs auto instrumentation', () => {
218218
};
219219

220220
await createRunner(__dirname, 'scenario.js')
221-
.withDockerCompose({ workingDirectory: [__dirname] })
221+
.withDockerCompose({
222+
workingDirectory: [__dirname],
223+
readyMatches: ['postgresjs-ready'],
224+
})
222225
.expect({ transaction: EXPECTED_TRANSACTION })
223226
.expect({ event: EXPECTED_ERROR_EVENT })
224227
.start()
@@ -438,7 +441,10 @@ describe('postgresjs auto instrumentation', () => {
438441

439442
await createRunner(__dirname, 'scenario.mjs')
440443
.withFlags('--import', `${__dirname}/instrument.mjs`)
441-
.withDockerCompose({ workingDirectory: [__dirname] })
444+
.withDockerCompose({
445+
workingDirectory: [__dirname],
446+
readyMatches: ['postgresjs-ready'],
447+
})
442448
.expect({ transaction: EXPECTED_TRANSACTION })
443449
.expect({ event: EXPECTED_ERROR_EVENT })
444450
.start()
@@ -532,7 +538,10 @@ describe('postgresjs auto instrumentation', () => {
532538

533539
await createRunner(__dirname, 'scenario-requestHook.js')
534540
.withFlags('--require', `${__dirname}/instrument-requestHook.cjs`)
535-
.withDockerCompose({ workingDirectory: [__dirname] })
541+
.withDockerCompose({
542+
workingDirectory: [__dirname],
543+
readyMatches: ['postgresjs-ready'],
544+
})
536545
.expect({ transaction: EXPECTED_TRANSACTION })
537546
.start()
538547
.completed();
@@ -625,7 +634,10 @@ describe('postgresjs auto instrumentation', () => {
625634

626635
await createRunner(__dirname, 'scenario-requestHook.mjs')
627636
.withFlags('--import', `${__dirname}/instrument-requestHook.mjs`)
628-
.withDockerCompose({ workingDirectory: [__dirname] })
637+
.withDockerCompose({
638+
workingDirectory: [__dirname],
639+
readyMatches: ['postgresjs-ready'],
640+
})
629641
.expect({ transaction: EXPECTED_TRANSACTION })
630642
.start()
631643
.completed();
@@ -706,7 +718,10 @@ describe('postgresjs auto instrumentation', () => {
706718
};
707719

708720
await createRunner(__dirname, 'scenario-url.cjs')
709-
.withDockerCompose({ workingDirectory: [__dirname] })
721+
.withDockerCompose({
722+
workingDirectory: [__dirname],
723+
readyMatches: ['postgresjs-ready'],
724+
})
710725
.expect({ transaction: EXPECTED_TRANSACTION })
711726
.start()
712727
.completed();
@@ -787,7 +802,10 @@ describe('postgresjs auto instrumentation', () => {
787802

788803
await createRunner(__dirname, 'scenario-url.mjs')
789804
.withFlags('--import', `${__dirname}/instrument.mjs`)
790-
.withDockerCompose({ workingDirectory: [__dirname] })
805+
.withDockerCompose({
806+
workingDirectory: [__dirname],
807+
readyMatches: ['postgresjs-ready'],
808+
})
791809
.expect({ transaction: EXPECTED_TRANSACTION })
792810
.start()
793811
.completed();
@@ -866,7 +884,10 @@ describe('postgresjs auto instrumentation', () => {
866884
};
867885

868886
await createRunner(__dirname, 'scenario-unsafe.cjs')
869-
.withDockerCompose({ workingDirectory: [__dirname] })
887+
.withDockerCompose({
888+
workingDirectory: [__dirname],
889+
readyMatches: ['postgresjs-ready'],
890+
})
870891
.expect({ transaction: EXPECTED_TRANSACTION })
871892
.start()
872893
.completed();
@@ -946,7 +967,10 @@ describe('postgresjs auto instrumentation', () => {
946967

947968
await createRunner(__dirname, 'scenario-unsafe.mjs')
948969
.withFlags('--import', `${__dirname}/instrument.mjs`)
949-
.withDockerCompose({ workingDirectory: [__dirname] })
970+
.withDockerCompose({
971+
workingDirectory: [__dirname],
972+
readyMatches: ['postgresjs-ready'],
973+
})
950974
.expect({ transaction: EXPECTED_TRANSACTION })
951975
.start()
952976
.completed();

0 commit comments

Comments
 (0)