Skip to content

test(node-integration-tests): Fix flaky postgresjs basic transaction/error ordering#21870

Merged
mydea merged 1 commit into
developfrom
fix/postgresjs-basic-flaky-envelope-order
Jul 1, 2026
Merged

test(node-integration-tests): Fix flaky postgresjs basic transaction/error ordering#21870
mydea merged 1 commit into
developfrom
fix/postgresjs-basic-flaky-envelope-order

Conversation

@github-actions

@github-actions github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Fixes the flaky postgresjs auto instrumentation > basic > should auto-instrument \postgres` package [esm]` Node integration test.

Root cause

The basic test is the only postgresjs test that expects two differently-typed envelopes — a transaction followed by an error event:

.expect({ transaction: EXPECTED_TRANSACTION })
.expect({ event: EXPECTED_ERROR_EVENT })

The scenario's final query targets the just-dropped "User" table, so it rejects with a PostgresError. That rejection propagates out of run() as an unhandled promise rejection, which Sentry captures on a later event-loop tick than the transaction (the transaction is captured synchronously when the root span ends). Because the two envelopes are produced on different ticks, their arrival order at the transport is not deterministic.

By default the test runner matches envelopes in order (expectedEnvelopes.shift()), so whenever the error event happened to reach the transport before the transaction, the runner threw Expected envelope item type 'transaction' but got 'event' and the test failed — a textbook intermittent flake. The other three describe blocks each expect only a single transaction envelope, which is why only basic flaked.

Fix

Add .unordered() to the basic runner chain so the two envelopes may arrive in either order. Both the transaction (with all its spans) and the error event are still fully asserted with the same content matchers — only the brittle arrival-order constraint is removed. This mirrors the existing precedent in suites/tracing/apollo-graphql/test.ts, which uses .unordered() for the same class of non-deterministic multi-envelope ordering.

Fixes #21790

…error ordering

Fixes #21790

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot requested a review from a team as a code owner July 1, 2026 06:49
@github-actions github-actions Bot requested review from JPeer264, andreiborza and mydea and removed request for a team July 1, 2026 06:49
@mydea mydea enabled auto-merge (squash) July 1, 2026 06:50
@mydea mydea merged commit 429cdaf into develop Jul 1, 2026
52 checks passed
@mydea mydea deleted the fix/postgresjs-basic-flaky-envelope-order branch July 1, 2026 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant