Skip to content

Commit c436876

Browse files
authored
Merge branch 'main' into NODE-7491
2 parents 9f7be0c + 1fc0e09 commit c436876

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
applyTo:
3+
- "test/spec/**/*.json"
4+
- "test/spec/**/*.yml"
5+
- "test/spec/**/README.md"
6+
---
7+
These are unified spec test files copied from the mongodb/specifications repo.
8+
Do not suggest changes to these files. They must match the upstream spec exactly.

test/integration/crud/find.test.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as sinon from 'sinon';
33

44
import {
55
Code,
6-
CursorResponse,
76
Long,
87
type MongoClient,
98
MongoServerError,
@@ -1075,29 +1074,29 @@ describe('Find', function () {
10751074
});
10761075

10771076
it(
1078-
'regression test (NODE-6878): CursorResponse.emptyGetMore contains all CursorResponse fields',
1077+
'regression test (NODE-6878): cursor can be rewound after limit-based exhaustion',
10791078
{ requires: { topology: 'sharded' } },
10801079
async function () {
10811080
const collection = client.db('rewind-regression').collection('bar');
10821081

10831082
await collection.deleteMany({});
10841083
await collection.insertMany(Array.from({ length: 4 }, (_, i) => ({ x: i })));
10851084

1086-
const getMoreSpy = sinon.spy(CursorResponse, 'emptyGetMore', ['get']);
1087-
10881085
const cursor = collection.find({}, { batchSize: 1, limit: 3 });
1089-
// emptyGetMore is used internally after limit + 1 documents have been iterated
1086+
// Iterate limit + 1 times to exercise the post-limit cursor path before rewind.
10901087
await cursor.next();
10911088
await cursor.next();
10921089
await cursor.next();
10931090
await cursor.next();
10941091

1095-
// assert that `emptyGetMore` is called. if it is not, this test
1096-
// always passes, even without the fix in NODE-6878.
1097-
expect(getMoreSpy.get).to.have.been.called;
1092+
// On servers < 9.0, mongos returns a non-zero cursorId even after the limit
1093+
// is satisfied, so the driver uses CursorResponse.emptyGetMore to avoid a
1094+
// wasted getMore. On 9.0+, mongos returns cursorId: 0 when the limit is
1095+
// reached. In both cases, rewinding and re-iterating the cursor must work.
10981096

1097+
// rewind + toArray must not throw. Before the NODE-6878 fix,
1098+
// this would fail with a TypeError from emptyGetMore lacking CursorResponse fields.
10991099
cursor.rewind();
1100-
11011100
await cursor.toArray();
11021101
}
11031102
);

0 commit comments

Comments
 (0)