diff --git a/test/integration/crud/find.test.ts b/test/integration/crud/find.test.ts index bb6fc2146e4..3d3ff8d4349 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,18 +1082,17 @@ 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 + // Iterate limit + 1 times to exercise the post-limit cursor path before rewind. await cursor.next(); await cursor.next(); 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();