@@ -221,7 +221,15 @@ func TestDatabase(t *testing.T) {
221
221
})
222
222
}
223
223
})
224
- mt .RunOpts ("batch size" , mtest .NewOptions ().MinServerVersion ("3.0" ), func (mt * mtest.T ) {
224
+
225
+ // For server versions below 3.0, we internally execute ListCollections() as a legacy
226
+ // OP_QUERY against the system.namespaces collection. Command monitoring upconversions
227
+ // translate this to a "find" command rather than "listCollections".
228
+ cmdMonitoringCmdName := "listCollections"
229
+ if mtest .CompareServerVersions (mtest .ServerVersion (), "3.0" ) < 0 {
230
+ cmdMonitoringCmdName = "find"
231
+ }
232
+ mt .Run ("batch size" , func (mt * mtest.T ) {
225
233
// Create two new collections so there will be three total.
226
234
createCollections (mt , 2 )
227
235
@@ -231,24 +239,25 @@ func TestDatabase(t *testing.T) {
231
239
assert .Nil (mt , err , "ListCollectionNames error: %v" , err )
232
240
233
241
evt := mt .GetStartedEvent ()
234
- assert .Equal (mt , "listCollections" , evt .CommandName , "expected 'listCollections' command to be sent, got %q" ,
242
+ assert .Equal (
243
+ mt ,
244
+ cmdMonitoringCmdName ,
245
+ evt .CommandName ,
246
+ "expected %q command to be sent, got %q" ,
247
+ cmdMonitoringCmdName ,
235
248
evt .CommandName )
236
249
_ , err = evt .Command .LookupErr ("cursor" , "batchSize" )
237
250
assert .Nil (mt , err , "expected command %s to contain key 'batchSize'" , evt .Command )
238
251
})
239
-
240
- // The BatchSize option is not honored for ListCollections operations on server version 2.6 due to an
241
- // inconsistency in the legacy OP_QUERY code path (GODRIVER-1937).
242
- cmdMonitoringMtOpts := mtest .NewOptions ().MinServerVersion ("3.0" )
243
- mt .RunOpts ("getMore commands are monitored" , cmdMonitoringMtOpts , func (mt * mtest.T ) {
252
+ mt .Run ("getMore commands are monitored" , func (mt * mtest.T ) {
244
253
createCollections (mt , 2 )
245
- assertGetMoreCommandsAreMonitored (mt , "listCollections" , func () (* mongo.Cursor , error ) {
254
+ assertGetMoreCommandsAreMonitored (mt , cmdMonitoringCmdName , func () (* mongo.Cursor , error ) {
246
255
return mt .DB .ListCollections (mtest .Background , bson.D {}, options .ListCollections ().SetBatchSize (2 ))
247
256
})
248
257
})
249
- mt .RunOpts ("killCursors commands are monitored" , cmdMonitoringMtOpts , func (mt * mtest.T ) {
258
+ mt .Run ("killCursors commands are monitored" , func (mt * mtest.T ) {
250
259
createCollections (mt , 2 )
251
- assertKillCursorsCommandsAreMonitored (mt , "listCollections" , func () (* mongo.Cursor , error ) {
260
+ assertKillCursorsCommandsAreMonitored (mt , cmdMonitoringCmdName , func () (* mongo.Cursor , error ) {
252
261
return mt .DB .ListCollections (mtest .Background , bson.D {}, options .ListCollections ().SetBatchSize (2 ))
253
262
})
254
263
})
0 commit comments