Skip to content

test(NODE-7513): relax regression test for emptyGetMore#4916

Open
tadjik1 wants to merge 2 commits intomainfrom
NODE-7513
Open

test(NODE-7513): relax regression test for emptyGetMore#4916
tadjik1 wants to merge 2 commits intomainfrom
NODE-7513

Conversation

@tadjik1
Copy link
Copy Markdown
Member

@tadjik1 tadjik1 commented Apr 10, 2026

Description

Summary of Changes

Remove the emptyGetMore spy assertion from the NODE-6878 regression test. The test now only verifies that cursor.rewind() works correctly after cursor exhaustion via limit, which is the actual regression being guarded.

Notes for Reviewers

On MongoDB 9.0+, mongos now returns cursorId: 0 on the getMore that delivers the final batch when a limit is reached. This means the driver's emptyGetMore optimization (which avoids a wasted getMore when the server returns a non-zero cursorId after the limit is satisfied) is never triggered on sharded topologies with 9.0+.

The spy assertion required emptyGetMore to be called, which can no longer happen on 9.0. The original comment noted that without the spy, "this test always passes, even without the fix in NODE-6878" - that was true because if emptyGetMore was never called, the buggy (incomplete) response object was never used, so rewind() would succeed trivially. Now that the NODE-6878 fix is merged and emptyGetMore is a proper CursorResponse, the spy is no longer needed as a guard against a vacuously passing test. The rewind assertion remains meaningful regardless of which code path exhausts the cursor.

What is the motivation for this change?

Release Highlight

Release notes highlight

Double check the following

  • Lint is passing (npm run check:lint)
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@tadjik1 tadjik1 marked this pull request as ready for review April 10, 2026 13:33
@tadjik1 tadjik1 requested a review from a team as a code owner April 10, 2026 13:33
Copilot AI review requested due to automatic review settings April 10, 2026 13:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR relaxes the NODE-6878 sharded regression test by removing the CursorResponse.emptyGetMore spy assertion, keeping the test focused on verifying that cursor.rewind() continues to work after the cursor is exhausted via limit.

Changes:

  • Removed the CursorResponse.emptyGetMore spy/assertion from the sharded NODE-6878 regression test.
  • Updated the test’s inline commentary to account for mongos behavior changes on MongoDB 9.0+.
Comments suppressed due to low confidence (1)

test/integration/crud/find.test.ts:1100

  • After rewinding, the test only awaits cursor.toArray() without asserting anything about the returned documents. This can allow the test to pass even if rewind() results in an incorrectly empty/partial iteration (as long as no exception is thrown). Consider asserting the expected number of documents (e.g., 3 for limit: 3) and/or their contents, and updating the test description accordingly since it no longer validates CursorResponse.emptyGetMore fields.
      cursor.rewind();

      await cursor.toArray();
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


// assert that `emptyGetMore` is called. if it is not, this test
// always passes, even without the fix in NODE-6878.
expect(getMoreSpy.get).to.have.been.called;
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.

This is the one and only assertion in this test, without it, what is it testing? The test title says that this is a regression test for NODE-6878 and is specifically about ensuring CursorResponse.emptyGetMore contains all CursorResponse fields. Based on your investigation regarding server 9.0, it would seem the test isn't relevant to servers 9.0+, so it should be skipped on just those configurations and continue being executed on the rest.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The spy doesn't actually test the fix - it only checks that emptyGetMore was called. The actual regression guard is cursor.rewind(); await cursor.toArray() - that's what would throw if emptyGetMore were broken again (returning an object without the proper CursorResponse shape causes documents.clear() to TypeError).

So there are two scenarios:

  1. Servers < 9.0 (sharded): emptyGetMore IS still called (server returns non-zero cursorId after limit). If someone reintroduced the bug, the rewind() + toArray() would throw - the regression is caught without the spy.
  2. Servers 9.0+ (sharded): emptyGetMore is never called (server returns cursorId: 0). The bug cannot manifest on this path - there's no broken object to trip over. So there's nothing to regress against.

@dariakp dariakp self-assigned this Apr 10, 2026
@dariakp dariakp added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Apr 10, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Primary Review In Review with primary reviewer, not yet ready for team's eyes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants