Skip to content

Commit 429cdaf

Browse files
test(node-integration-tests): Fix flaky postgresjs basic transaction/error ordering (#21870)
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`: ```ts .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 Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 35998e6 commit 429cdaf

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

  • dev-packages/node-integration-tests/suites/tracing/postgresjs

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ describe('postgresjs auto instrumentation', () => {
228228
.withDockerCompose({ workingDirectory: [__dirname] })
229229
.expect({ transaction: EXPECTED_TRANSACTION })
230230
.expect({ event: EXPECTED_ERROR_EVENT })
231+
// The error event is captured via an unhandled rejection processed on a later tick than
232+
// the transaction, so the two envelopes can reach the transport in either order.
233+
.unordered()
231234
.start()
232235
.completed();
233236
});

0 commit comments

Comments
 (0)