@@ -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
} )
@@ -35,7 +35,7 @@ describe('AbstractCursor', function () {
35
35
const commands = [ ] ;
36
36
client . on ( 'commandStarted' , filterForCommands ( [ 'getMore' ] , commands ) ) ;
37
37
38
- const coll = client . db ( ) . collection ( 'find_cursor ' ) ;
38
+ const coll = client . db ( ) . collection ( 'abstract_cursor ' ) ;
39
39
const cursor = coll . find ( { } , { batchSize : 2 } ) ;
40
40
this . defer ( ( ) => cursor . close ( ) ) ;
41
41
@@ -56,7 +56,7 @@ describe('AbstractCursor', function () {
56
56
const commands = [ ] ;
57
57
client . on ( 'commandStarted' , filterForCommands ( [ 'killCursors' ] , commands ) ) ;
58
58
59
- const coll = client . db ( ) . collection ( 'find_cursor ' ) ;
59
+ const coll = client . db ( ) . collection ( 'abstract_cursor ' ) ;
60
60
const cursor = coll . find ( { } , { batchSize : 2 } ) ;
61
61
cursor . next ( err => {
62
62
expect ( err ) . to . not . exist ;
@@ -75,7 +75,7 @@ describe('AbstractCursor', function () {
75
75
const commands = [ ] ;
76
76
client . on ( 'commandStarted' , filterForCommands ( [ 'killCursors' ] , commands ) ) ;
77
77
78
- const coll = client . db ( ) . collection ( 'find_cursor ' ) ;
78
+ const coll = client . db ( ) . collection ( 'abstract_cursor ' ) ;
79
79
const cursor = coll . find ( { } , { batchSize : 2 } ) ;
80
80
cursor . toArray ( err => {
81
81
expect ( err ) . to . not . exist ;
@@ -95,7 +95,7 @@ describe('AbstractCursor', function () {
95
95
const commands = [ ] ;
96
96
client . on ( 'commandStarted' , filterForCommands ( [ 'killCursors' ] , commands ) ) ;
97
97
98
- const coll = client . db ( ) . collection ( 'find_cursor ' ) ;
98
+ const coll = client . db ( ) . collection ( 'abstract_cursor ' ) ;
99
99
const cursor = coll . find ( { } , { batchSize : 2 } ) ;
100
100
cursor . close ( err => {
101
101
expect ( err ) . to . not . exist ;
@@ -110,7 +110,7 @@ describe('AbstractCursor', function () {
110
110
it (
111
111
'should iterate each document in a cursor' ,
112
112
withClientV2 ( function ( client , done ) {
113
- const coll = client . db ( ) . collection ( 'find_cursor ' ) ;
113
+ const coll = client . db ( ) . collection ( 'abstract_cursor ' ) ;
114
114
const cursor = coll . find ( { } , { batchSize : 2 } ) ;
115
115
116
116
const bag = [ ] ;
@@ -160,45 +160,85 @@ 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
} ) ;
194
234
} ) ;
195
235
} )
196
236
) ;
197
237
198
- it (
199
- 'should end an implicit session on rewind' ,
200
- withClientV2 ( function ( client , done ) {
201
- const coll = client . db ( ) . collection ( 'rewind ' ) ;
238
+ it ( 'should end an implicit session on rewind' , {
239
+ metadata : { requires : { mongodb : '>=3.6' } } ,
240
+ test : withClientV2 ( function ( client , done ) {
241
+ const coll = client . db ( ) . collection ( 'abstract_cursor ' ) ;
202
242
const cursor = coll . find ( { } , { batchSize : 1 } ) ;
203
243
this . defer ( ( ) => cursor . close ( ) ) ;
204
244
@@ -213,12 +253,12 @@ describe('AbstractCursor', function () {
213
253
done ( ) ;
214
254
} ) ;
215
255
} )
216
- ) ;
256
+ } ) ;
217
257
218
- it (
219
- 'should not end an explicit session on rewind' ,
220
- withClientV2 ( function ( client , done ) {
221
- const coll = client . db ( ) . collection ( 'rewind ' ) ;
258
+ it ( 'should not end an explicit session on rewind' , {
259
+ metadata : { requires : { mongodb : '>=3.6' } } ,
260
+ test : withClientV2 ( function ( client , done ) {
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 } ) ;
@@ -236,6 +276,6 @@ describe('AbstractCursor', function () {
236
276
session . endSession ( done ) ;
237
277
} ) ;
238
278
} )
239
- ) ;
279
+ } ) ;
240
280
} ) ;
241
281
} ) ;
0 commit comments