@@ -3,7 +3,7 @@ const { assert: test } = require('../shared');
3
3
const { expect } = require ( 'chai' ) ;
4
4
const sinon = require ( 'sinon' ) ;
5
5
const { setTimeout } = require ( 'timers' ) ;
6
- const { Code, ObjectId, Long, Binary, ReturnDocument } = require ( '../../mongodb' ) ;
6
+ const { Code, ObjectId, Long, Binary, ReturnDocument, CursorResponse } = require ( '../../mongodb' ) ;
7
7
8
8
describe ( 'Find' , function ( ) {
9
9
let client ;
@@ -2388,4 +2388,32 @@ describe('Find', function () {
2388
2388
} ) ;
2389
2389
} ) ;
2390
2390
} ) ;
2391
+
2392
+ it (
2393
+ 'regression test (NODE-6878): CursorResponse.emptyGetMore contains all CursorResponse fields' ,
2394
+ { requires : { topology : 'sharded' } } ,
2395
+ async function ( ) {
2396
+ const collection = client . db ( 'rewind-regression' ) . collection ( 'bar' ) ;
2397
+
2398
+ await collection . deleteMany ( { } ) ;
2399
+ await collection . insertMany ( Array . from ( { length : 4 } , ( _ , i ) => ( { x : i } ) ) ) ;
2400
+
2401
+ const getMoreSpy = sinon . spy ( CursorResponse , 'emptyGetMore' , [ 'get' ] ) ;
2402
+
2403
+ const cursor = collection . find ( { } , { batchSize : 1 , limit : 3 } ) ;
2404
+ // emptyGetMore is used internally after limit + 1 documents have been iterated
2405
+ await cursor . next ( ) ;
2406
+ await cursor . next ( ) ;
2407
+ await cursor . next ( ) ;
2408
+ await cursor . next ( ) ;
2409
+
2410
+ // assert that `emptyGetMore` is called. if it is not, this test
2411
+ // always passes, even without the fix in NODE-6878.
2412
+ expect ( getMoreSpy . get ) . to . have . been . called ;
2413
+
2414
+ cursor . rewind ( ) ;
2415
+
2416
+ await cursor . toArray ( ) ;
2417
+ }
2418
+ ) ;
2391
2419
} ) ;
0 commit comments