test(node-integration-tests): Fix flaky postgresjs basic transaction/error ordering#21870
Merged
Merged
Conversation
…error ordering Fixes #21790 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
mydea
approved these changes
Jul 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the flaky
postgresjs auto instrumentation > basic > should auto-instrument \postgres` package [esm]` Node integration test.Root cause
The
basictest is the only postgresjs test that expects two differently-typed envelopes — atransactionfollowed by an errorevent:The scenario's final query targets the just-dropped
"User"table, so it rejects with aPostgresError. That rejection propagates out ofrun()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 threwExpected 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 onlybasicflaked.Fix
Add
.unordered()to thebasicrunner 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 insuites/tracing/apollo-graphql/test.ts, which uses.unordered()for the same class of non-deterministic multi-envelope ordering.Fixes #21790