@@ -218,6 +218,34 @@ func TestCursor(t *testing.T) {
218
218
assert .Equal (mt , failpointData .ErrorCode , mongoErr .Code , "expected code %v, got: %v" , failpointData .ErrorCode , mongoErr .Code )
219
219
})
220
220
})
221
+ // For versions < 3.2, the first find will get all the documents
222
+ mt .RunOpts ("set batchSize" , mtest .NewOptions ().MinServerVersion ("3.2" ), func (mt * mtest.T ) {
223
+ initCollection (mt , mt .Coll )
224
+ mt .ClearEvents ()
225
+
226
+ // create cursor with batchSize 0
227
+ cursor , err := mt .Coll .Find (mtest .Background , bson.D {}, options .Find ().SetBatchSize (0 ))
228
+ assert .Nil (mt , err , "Find error: %v" , err )
229
+ defer cursor .Close (mtest .Background )
230
+ evt := mt .GetStartedEvent ()
231
+ assert .Equal (mt , "find" , evt .CommandName , "expected 'find' event, got '%v'" , evt .CommandName )
232
+ sizeVal , err := evt .Command .LookupErr ("batchSize" )
233
+ assert .Nil (mt , err , "expected find command to have batchSize" )
234
+ batchSize := sizeVal .Int32 ()
235
+ assert .Equal (mt , int32 (0 ), batchSize , "expected batchSize 0, got %v" , batchSize )
236
+
237
+ // make sure that the getMore sends the new batchSize
238
+ batchCursor := mongo .BatchCursorFromCursor (cursor )
239
+ batchCursor .SetBatchSize (4 )
240
+ assert .True (mt , cursor .Next (mtest .Background ), "expected Next true, got false" )
241
+ evt = mt .GetStartedEvent ()
242
+ assert .NotNil (mt , evt , "expected getMore event, got nil" )
243
+ assert .Equal (mt , "getMore" , evt .CommandName , "expected 'getMore' event, got '%v'" , evt .CommandName )
244
+ sizeVal , err = evt .Command .LookupErr ("batchSize" )
245
+ assert .Nil (mt , err , "expected getMore command to have batchSize" )
246
+ batchSize = sizeVal .Int32 ()
247
+ assert .Equal (mt , int32 (4 ), batchSize , "expected batchSize 4, got %v" , batchSize )
248
+ })
221
249
}
222
250
223
251
type tryNextCursor interface {
0 commit comments