Commit 429cdaf
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
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
228 | 228 | | |
229 | 229 | | |
230 | 230 | | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
231 | 234 | | |
232 | 235 | | |
233 | 236 | | |
| |||
0 commit comments