Skip to content

test(unit): fix flaky mongo connection test - #41526

Merged
dionisio-bot[bot] merged 1 commit into
developfrom
fix-flaky-connection-test
Jul 22, 2026
Merged

test(unit): fix flaky mongo connection test#41526
dionisio-bot[bot] merged 1 commit into
developfrom
fix-flaky-connection-test

Conversation

@sampaiodiego

@sampaiodiego sampaiodiego commented Jul 22, 2026

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

Problem

Connection.spec.ts had a flaky reconnect test (should reset retryCount on a successful connection…) that intermittently failed in CI with Expected: "connected" / Received: "connecting".

The reconnect helper blocks waited on connection.once('connection', …), but the 'connection' event fires on every status transition. During a reconnect the sequence is reconnecting → connecting → connected, so once resolved on the very first emission ('reconnecting') — two transitions early. That let handleConnection resolve before the handshake finished, so the synchronous expect(connection.status).toBe('connected') on the next line raced the message delivery. It passed on fast/idle machines and lost under CI load.

Fix

Replaced the once('connection', …) waiters with a value-gated on('connection', …) listener that only resolves once status actually reaches 'connected', then detaches itself. Applied to all four reconnect blocks in the spec. This keeps the same observation channel and leaves every assertion unchanged — it only stops resolving on the intermediate 'reconnecting' state.

No production code changed; this is purely a test-synchronization fix.

Issue(s)

Steps to test or reproduce

Further comments

Review in cubic

Summary by CodeRabbit

  • Tests
    • Improved reconnect test reliability by waiting specifically for confirmed connected states.
    • Updated coverage for retry-budget resets and stale socket closure scenarios.

Task: ARCH-2292

@dionisio-bot

dionisio-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 61fc9e0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Reconnect-related connection tests now wait for a 'connected' event status before continuing, covering reconnect, retry-budget reset, and stale socket close scenarios.

Changes

Connection Test Reliability

Layer / File(s) Summary
Reconnect event synchronization
packages/ddp-client/__tests__/Connection.spec.ts
Reconnect waits use temporary listeners that resolve only on 'connected' status and unregister afterward across four connection tests.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: type: chore

Suggested reviewers: ggazzo

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: fixing a flaky MongoDB connection unit test.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 1 file

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/ddp-client/__tests__/Connection.spec.ts
@ggazzo ggazzo added the stat: QA assured Means it has been tested and approved by a company insider label Jul 22, 2026
@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.68%. Comparing base (eb99fc4) to head (61fc9e0).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop   #41526   +/-   ##
========================================
  Coverage    68.68%   68.68%           
========================================
  Files         4135     4135           
  Lines       160461   160461           
  Branches     29186    29251   +65     
========================================
+ Hits        110215   110217    +2     
+ Misses       45137    45135    -2     
  Partials      5109     5109           
Flag Coverage Δ
e2e 58.86% <ø> (-0.01%) ⬇️
e2e-api 45.34% <ø> (-0.28%) ⬇️
unit 70.69% <ø> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sampaiodiego

Copy link
Copy Markdown
Member Author

/jira ARCH-2200

@sampaiodiego sampaiodiego added this to the 8.8.0 milestone Jul 22, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Jul 22, 2026
@dionisio-bot
dionisio-bot Bot added this pull request to the merge queue Jul 22, 2026
Merged via the queue into develop with commit 0c15350 Jul 22, 2026
56 checks passed
@dionisio-bot
dionisio-bot Bot deleted the fix-flaky-connection-test branch July 22, 2026 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge type: chore

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants