@@ -3,7 +3,7 @@ const { assert: test } = require('../shared');
33const  {  expect }  =  require ( 'chai' ) ; 
44const  sinon  =  require ( 'sinon' ) ; 
55const  {  setTimeout }  =  require ( 'timers' ) ; 
6- const  {  Code,  ObjectId,  Long,  Binary,  ReturnDocument }  =  require ( '../../mongodb' ) ; 
6+ const  {  Code,  ObjectId,  Long,  Binary,  ReturnDocument,  CursorResponse  }  =  require ( '../../mongodb' ) ; 
77
88describe ( 'Find' ,  function  ( )  { 
99  let  client ; 
@@ -2388,4 +2388,32 @@ describe('Find', function () {
23882388      } ) ; 
23892389    } ) ; 
23902390  } ) ; 
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+   ) ; 
23912419} ) ; 
0 commit comments