@@ -22,7 +22,7 @@ describe('AbstractCursor', function () {
22
22
before (
23
23
withClientV2 ( ( client , done ) => {
24
24
const docs = [ { a : 1 } , { a : 2 } , { a : 3 } , { a : 4 } , { a : 5 } , { a : 6 } ] ;
25
- const coll = client . db ( ) . collection ( 'find_cursor ' ) ;
25
+ const coll = client . db ( ) . collection ( 'abstract_cursor ' ) ;
26
26
const tryNextColl = client . db ( ) . collection ( 'try_next' ) ;
27
27
coll . drop ( ( ) => tryNextColl . drop ( ( ) => coll . insertMany ( docs , done ) ) ) ;
28
28
} )
@@ -160,34 +160,74 @@ describe('AbstractCursor', function () {
160
160
) ;
161
161
} ) ;
162
162
163
- context ( '#rewind' , function ( ) {
164
- beforeEach (
163
+ context ( '#clone' , function ( ) {
164
+ it (
165
+ 'should clone a find cursor' ,
165
166
withClientV2 ( function ( client , done ) {
166
- const coll = client . db ( ) . collection ( 'rewind' ) ;
167
- coll . drop ( ( ) => {
168
- coll . insertMany ( [ { } , { } ] , err => {
167
+ const coll = client . db ( ) . collection ( 'abstract_cursor' ) ;
168
+ const cursor = coll . find ( { } ) ;
169
+ this . defer ( ( ) => cursor . close ( ) ) ;
170
+
171
+ cursor . toArray ( ( err , docs ) => {
172
+ expect ( err ) . to . not . exist ;
173
+ expect ( docs ) . to . have . length ( 6 ) ;
174
+ expect ( cursor ) . property ( 'closed' ) . to . be . true ;
175
+
176
+ const clonedCursor = cursor . clone ( ) ;
177
+ this . defer ( ( ) => clonedCursor . close ( ) ) ;
178
+
179
+ clonedCursor . toArray ( ( err , docs ) => {
180
+ expect ( err ) . to . not . exist ;
181
+ expect ( docs ) . to . have . length ( 6 ) ;
182
+ expect ( clonedCursor ) . property ( 'closed' ) . to . be . true ;
183
+ done ( ) ;
184
+ } ) ;
185
+ } ) ;
186
+ } )
187
+ ) ;
188
+
189
+ it (
190
+ 'should clone an aggregate cursor' ,
191
+ withClientV2 ( function ( client , done ) {
192
+ const coll = client . db ( ) . collection ( 'abstract_cursor' ) ;
193
+ const cursor = coll . aggregate ( [ { $match : { } } ] ) ;
194
+ this . defer ( ( ) => cursor . close ( ) ) ;
195
+
196
+ cursor . toArray ( ( err , docs ) => {
197
+ expect ( err ) . to . not . exist ;
198
+ expect ( docs ) . to . have . length ( 6 ) ;
199
+ expect ( cursor ) . property ( 'closed' ) . to . be . true ;
200
+
201
+ const clonedCursor = cursor . clone ( ) ;
202
+ this . defer ( ( ) => clonedCursor . close ( ) ) ;
203
+
204
+ clonedCursor . toArray ( ( err , docs ) => {
169
205
expect ( err ) . to . not . exist ;
206
+ expect ( docs ) . to . have . length ( 6 ) ;
207
+ expect ( clonedCursor ) . property ( 'closed' ) . to . be . true ;
170
208
done ( ) ;
171
209
} ) ;
172
210
} ) ;
173
211
} )
174
212
) ;
213
+ } ) ;
175
214
215
+ context ( '#rewind' , function ( ) {
176
216
it (
177
217
'should rewind a cursor' ,
178
218
withClientV2 ( function ( client , done ) {
179
- const coll = client . db ( ) . collection ( 'rewind ' ) ;
219
+ const coll = client . db ( ) . collection ( 'abstract_cursor ' ) ;
180
220
const cursor = coll . find ( { } ) ;
181
221
this . defer ( ( ) => cursor . close ( ) ) ;
182
222
183
223
cursor . toArray ( ( err , docs ) => {
184
224
expect ( err ) . to . not . exist ;
185
- expect ( docs ) . to . have . length ( 2 ) ;
225
+ expect ( docs ) . to . have . length ( 6 ) ;
186
226
187
227
cursor . rewind ( ) ;
188
228
cursor . toArray ( ( err , docs ) => {
189
229
expect ( err ) . to . not . exist ;
190
- expect ( docs ) . to . have . length ( 2 ) ;
230
+ expect ( docs ) . to . have . length ( 6 ) ;
191
231
192
232
done ( ) ;
193
233
} ) ;
@@ -198,7 +238,7 @@ describe('AbstractCursor', function () {
198
238
it (
199
239
'should end an implicit session on rewind' ,
200
240
withClientV2 ( function ( client , done ) {
201
- const coll = client . db ( ) . collection ( 'rewind ' ) ;
241
+ const coll = client . db ( ) . collection ( 'abstract_cursor ' ) ;
202
242
const cursor = coll . find ( { } , { batchSize : 1 } ) ;
203
243
this . defer ( ( ) => cursor . close ( ) ) ;
204
244
@@ -218,7 +258,7 @@ describe('AbstractCursor', function () {
218
258
it (
219
259
'should not end an explicit session on rewind' ,
220
260
withClientV2 ( function ( client , done ) {
221
- const coll = client . db ( ) . collection ( 'rewind ' ) ;
261
+ const coll = client . db ( ) . collection ( 'abstract_cursor ' ) ;
222
262
const session = client . startSession ( ) ;
223
263
224
264
const cursor = coll . find ( { } , { batchSize : 1 , session } ) ;
0 commit comments