Skip to content

Conversation

@hank95179
Copy link
Contributor

@hank95179 hank95179 commented Nov 7, 2025

Issue link

This Pull Request is linked to issue (URL): #4923

What & Why (Summary)

The PubSub › test pubsub channels_%p test sporadically misses test_channel2. Root causes are cross-run/parallel contamination (shared channel names) and a small timing gap between subscription establishment and observability via pubsubChannels().

This PR stabilizes the test with minimal changes:

  1. Unique naming isolation: Introduce a per-run runId and suffix all channels/patterns with :${runId} to avoid interference across tests or previous runs.
  2. Bounded wait before assert: Add a short polling window (up to 60 iterations × 50 ms) before final assertions so the test observes the expected set once subscriptions are visible.

No production code is changed; only the test data and assert timing are adjusted.

Details of the change

  • Add const runId = String(getRandomKey());
  • Change test_channel1|test_channel2|some_channel3 and patterns to …:${runId}
  • Poll pubsubChannels() (and pubsubChannels({ pattern })) until the exact expected set is observed or the bounded window expires, then perform the final expect.
  • Bind the “non-matching pattern” to non_matching_*:${runId} to avoid accidental matches from other runs.

Why this fixes the flake

  • Isolation removes cross-test contamination from shared channel names.
  • Bounded wait absorbs the small timing window between subscription setup and visibility in pubsubChannels().

Risk & Alternatives

  • Low risk: Test-only change; does not affect runtime behavior.
  • Alternatives (e.g., enforcing global serial execution or heavy global cleanup) are broader in scope and slow down CI. This PR keeps the fix local and minimal.

How I verified

  • Repeated runs in local/container environments for tests/PubSub.test.ts targeting channels_true (both in-band and parallel CI-style) no longer show the missing test_channel2 diff.
  • Other PubSub tests remain unaffected.

@hank95179 hank95179 requested a review from a team as a code owner November 7, 2025 05:42
@hank95179 hank95179 force-pushed the fix/node-pubsub-channels-stabilize branch from 959895d to 86f5e2e Compare November 7, 2025 05:59
@hank95179 hank95179 force-pushed the fix/node-pubsub-channels-stabilize branch from 86f5e2e to 0c50874 Compare November 7, 2025 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants