From cfa3e10a363cd22ab2d3c40b694e5138f477b327 Mon Sep 17 00:00:00 2001 From: Sergey Zelenov Date: Fri, 10 Apr 2026 14:06:28 +0200 Subject: [PATCH 1/2] test(NODE-7513): relax regression test for emptyGetMore --- test/integration/crud/find.test.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test/integration/crud/find.test.ts b/test/integration/crud/find.test.ts index bb6fc2146e4..cb706b1ad82 100644 --- a/test/integration/crud/find.test.ts +++ b/test/integration/crud/find.test.ts @@ -3,7 +3,6 @@ import * as sinon from 'sinon'; import { Code, - CursorResponse, Long, type MongoClient, MongoServerError, @@ -1083,8 +1082,6 @@ describe('Find', function () { await collection.deleteMany({}); await collection.insertMany(Array.from({ length: 4 }, (_, i) => ({ x: i }))); - const getMoreSpy = sinon.spy(CursorResponse, 'emptyGetMore', ['get']); - const cursor = collection.find({}, { batchSize: 1, limit: 3 }); // emptyGetMore is used internally after limit + 1 documents have been iterated await cursor.next(); @@ -1092,9 +1089,10 @@ describe('Find', function () { await cursor.next(); await cursor.next(); - // 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; + // On servers < 9.0, mongos returns a non-zero cursorId even after the limit + // is satisfied, so the driver uses CursorResponse.emptyGetMore to avoid a + // wasted getMore. On 9.0+, mongos returns cursorId: 0 when the limit is + // reached. In both cases, rewinding and re-iterating the cursor must work. cursor.rewind(); From 7fff5dfda21d63efeeb4df6c7829245a7e1f55d6 Mon Sep 17 00:00:00 2001 From: Sergey Zelenov Date: Fri, 10 Apr 2026 15:59:48 +0200 Subject: [PATCH 2/2] update the comment Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- test/integration/crud/find.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/crud/find.test.ts b/test/integration/crud/find.test.ts index cb706b1ad82..3d3ff8d4349 100644 --- a/test/integration/crud/find.test.ts +++ b/test/integration/crud/find.test.ts @@ -1083,7 +1083,7 @@ describe('Find', function () { await collection.insertMany(Array.from({ length: 4 }, (_, i) => ({ x: i }))); const cursor = collection.find({}, { batchSize: 1, limit: 3 }); - // emptyGetMore is used internally after limit + 1 documents have been iterated + // Iterate limit + 1 times to exercise the post-limit cursor path before rewind. await cursor.next(); await cursor.next(); await cursor.next();