Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions test/integration/crud/find.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as sinon from 'sinon';

import {
Code,
CursorResponse,
Long,
type MongoClient,
MongoServerError,
Expand Down Expand Up @@ -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
Comment thread
tadjik1 marked this conversation as resolved.
Outdated
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;
Comment thread
dariakp marked this conversation as resolved.
// 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();

Expand Down
Loading