test(node): stabilize pubsub channels (unique runId + bounded wait) #4954
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.
Issue link
This Pull Request is linked to issue (URL): #4923
What & Why (Summary)
The
PubSub › test pubsub channels_%ptest sporadically missestest_channel2. Root causes are cross-run/parallel contamination (shared channel names) and a small timing gap between subscription establishment and observability viapubsubChannels().This PR stabilizes the test with minimal changes:
runIdand suffix all channels/patterns with:${runId}to avoid interference across tests or previous runs.No production code is changed; only the test data and assert timing are adjusted.
Details of the change
const runId = String(getRandomKey());test_channel1|test_channel2|some_channel3and patterns to…:${runId}pubsubChannels()(andpubsubChannels({ pattern })) until the exact expected set is observed or the bounded window expires, then perform the finalexpect.non_matching_*:${runId}to avoid accidental matches from other runs.Why this fixes the flake
pubsubChannels().Risk & Alternatives
How I verified
tests/PubSub.test.tstargetingchannels_true(both in-band and parallel CI-style) no longer show the missingtest_channel2diff.PubSubtests remain unaffected.