...

Text file src/go.mongodb.org/mongo-driver/testdata/run-command/runCursorCommand.yml

Documentation: go.mongodb.org/mongo-driver/testdata/run-command

     1description: runCursorCommand
     2
     3schemaVersion: '1.9'
     4
     5createEntities:
     6  - client:
     7      id: &client client
     8      useMultipleMongoses: false
     9      observeEvents: [commandStartedEvent, connectionReadyEvent, connectionCheckedOutEvent, connectionCheckedInEvent]
    10  - session:
    11      id: &session session
    12      client: *client
    13  - database:
    14      id: &db db
    15      client: *client
    16      databaseName: *db
    17  - collection:
    18      id: &collection collection
    19      database: *db
    20      collectionName: *collection
    21
    22initialData:
    23  - collectionName: collection
    24    databaseName: *db
    25    documents: &documents
    26      - { _id: 1, x: 11 }
    27      - { _id: 2, x: 22 }
    28      - { _id: 3, x: 33 }
    29      - { _id: 4, x: 44 }
    30      - { _id: 5, x: 55 }
    31
    32tests:
    33  # This is what this API was invented to do.
    34  - description: successfully executes checkMetadataConsistency cursor creating command
    35    runOnRequirements:
    36      - minServerVersion: '7.0'
    37        topologies: [sharded]
    38    operations:
    39      - name: runCursorCommand
    40        object: *db
    41        arguments:
    42          commandName: checkMetadataConsistency
    43          command: { checkMetadataConsistency: 1 }
    44    expectEvents:
    45      - client: *client
    46        eventType: command
    47        events:
    48          - commandStartedEvent:
    49              command:
    50                checkMetadataConsistency: 1
    51                $db: *db
    52                lsid: { $$exists: true }
    53              commandName: checkMetadataConsistency
    54
    55  - description: errors if the command response is not a cursor
    56    operations:
    57      - name: createCommandCursor
    58        object: *db
    59        arguments:
    60          commandName: ping
    61          command: { ping: 1 }
    62        expectError:
    63          isClientError: true
    64
    65
    66  # Driver Sessions
    67  - description: creates an implicit session that is reused across getMores
    68    operations:
    69      - name: runCursorCommand
    70        object: *db
    71        arguments:
    72          commandName: find
    73          command: { find: *collection, batchSize: 2 }
    74        expectResult: *documents
    75      - name: assertSameLsidOnLastTwoCommands
    76        object: testRunner
    77        arguments:
    78          client: *client
    79    expectEvents:
    80      - client: *client
    81        eventType: command
    82        events:
    83          - commandStartedEvent:
    84              command:
    85                find: *collection
    86                batchSize: 2
    87                $db: *db
    88                lsid: { $$exists: true }
    89              commandName: find
    90          - commandStartedEvent:
    91              command:
    92                getMore: { $$type: [int, long] }
    93                collection: *collection
    94                $db: *db
    95                lsid: { $$exists: true }
    96              commandName: getMore
    97
    98  - description: accepts an explicit session that is reused across getMores
    99    operations:
   100      - name: runCursorCommand
   101        object: *db
   102        arguments:
   103          commandName: find
   104          session: *session
   105          command: { find: *collection, batchSize: 2 }
   106        expectResult: *documents
   107      - name: assertSameLsidOnLastTwoCommands
   108        object: testRunner
   109        arguments:
   110          client: *client
   111    expectEvents:
   112      - client: *client
   113        eventType: command
   114        events:
   115          - commandStartedEvent:
   116              command:
   117                find: *collection
   118                batchSize: 2
   119                $db: *db
   120                lsid: { $$sessionLsid: *session }
   121              commandName: find
   122          - commandStartedEvent:
   123              command:
   124                getMore: { $$type: [int, long] }
   125                collection: *collection
   126                $db: *db
   127                lsid: { $$sessionLsid: *session }
   128              commandName: getMore
   129
   130  # Load Balancers
   131  - description: returns pinned connections to the pool when the cursor is exhausted
   132    runOnRequirements:
   133      - topologies: [ load-balanced ]
   134    operations:
   135      - name: createCommandCursor
   136        object: *db
   137        arguments:
   138          commandName: find
   139          batchSize: 2
   140          session: *session
   141          command: { find: *collection, batchSize: 2 }
   142        saveResultAsEntity: &cursor cursor
   143      - name: assertNumberConnectionsCheckedOut
   144        object: testRunner
   145        arguments:
   146          client: *client
   147          connections: 1
   148      - name: iterateUntilDocumentOrError
   149        object: *cursor
   150        expectResult: { _id: 1, x: 11 }
   151      - name: iterateUntilDocumentOrError
   152        object: *cursor
   153        expectResult: { _id: 2, x: 22 }
   154      - name: iterateUntilDocumentOrError
   155        object: *cursor
   156        expectResult: { _id: 3, x: 33 }
   157      - name: iterateUntilDocumentOrError
   158        object: *cursor
   159        expectResult: { _id: 4, x: 44 }
   160      - name: iterateUntilDocumentOrError
   161        object: *cursor
   162        expectResult: { _id: 5, x: 55 }
   163      - name: assertNumberConnectionsCheckedOut
   164        object: testRunner
   165        arguments:
   166          client: *client
   167          connections: 0
   168    expectEvents:
   169      - client: *client
   170        eventType: command
   171        events:
   172          - commandStartedEvent:
   173              command:
   174                find: *collection
   175                batchSize: 2
   176                $db: *db
   177                lsid: { $$sessionLsid: *session }
   178              commandName: find # 2 documents
   179          - commandStartedEvent:
   180              command:
   181                getMore: { $$type: [int, long] }
   182                collection: *collection
   183                $db: *db
   184                lsid: { $$sessionLsid: *session }
   185              commandName: getMore # 2 documents
   186          - commandStartedEvent:
   187              command:
   188                getMore: { $$type: [int, long] }
   189                collection: *collection
   190                $db: *db
   191                lsid: { $$sessionLsid: *session }
   192              commandName: getMore # 1 document
   193              # Total documents: 5
   194      - client: *client
   195        eventType: cmap
   196        events:
   197          - connectionReadyEvent: {}
   198          - connectionCheckedOutEvent: {}
   199          - connectionCheckedInEvent: {}
   200
   201  - description: returns pinned connections to the pool when the cursor is closed
   202    runOnRequirements:
   203      - topologies: [ load-balanced ]
   204    operations:
   205      - name: createCommandCursor
   206        object: *db
   207        arguments:
   208          commandName: find
   209          command: { find: *collection, batchSize: 2 }
   210        saveResultAsEntity: *cursor
   211      - name: assertNumberConnectionsCheckedOut
   212        object: testRunner
   213        arguments:
   214          client: *client
   215          connections: 1
   216      - name: close
   217        object: *cursor
   218      - name: assertNumberConnectionsCheckedOut
   219        object: testRunner
   220        arguments:
   221          client: *client
   222          connections: 0
   223
   224  # Iterating the Cursor / Executing GetMores
   225  - description: supports configuring getMore batchSize
   226    operations:
   227      - name: runCursorCommand
   228        object: *db
   229        arguments:
   230          commandName: find
   231          batchSize: 5
   232          command: { find: *collection, batchSize: 1 }
   233        expectResult: *documents
   234    expectEvents:
   235      - client: *client
   236        eventType: command
   237        events:
   238          - commandStartedEvent:
   239              command:
   240                find: *collection
   241                batchSize: 1
   242                $db: *db
   243                lsid: { $$exists: true }
   244              commandName: find
   245          - commandStartedEvent:
   246              command:
   247                getMore: { $$type: [int, long] }
   248                collection: *collection
   249                batchSize: 5
   250                $db: *db
   251                lsid: { $$exists: true }
   252              commandName: getMore
   253
   254  - description: supports configuring getMore maxTimeMS
   255    operations:
   256      - name: runCursorCommand
   257        object: *db
   258        arguments:
   259          commandName: find
   260          maxTimeMS: 300
   261          command: { find: *collection, maxTimeMS: 200, batchSize: 1 }
   262        ignoreResultAndError: true
   263    expectEvents:
   264      - client: *client
   265        eventType: command
   266        # The getMore should receive an error here because we do not have the right kind of cursor
   267        # So drivers should run a killCursors, but neither the error nor the killCursors command is relevant to this test
   268        ignoreExtraEvents: true
   269        events:
   270          - commandStartedEvent:
   271              command:
   272                find: *collection
   273                maxTimeMS: 200
   274                batchSize: 1
   275                $db: *db
   276                lsid: { $$exists: true }
   277              commandName: find
   278          - commandStartedEvent:
   279              command:
   280                getMore: { $$type: [int, long] }
   281                collection: *collection
   282                $db: *db
   283                maxTimeMS: 300
   284                lsid: { $$exists: true }
   285              commandName: getMore
   286
   287  - description: supports configuring getMore comment
   288    runOnRequirements:
   289      - minServerVersion: '4.4'
   290    operations:
   291      - name: runCursorCommand
   292        object: *db
   293        arguments:
   294          commandName: find
   295          comment: { hello: 'getMore' }
   296          command: { find: *collection, batchSize: 1, comment: { hello: 'find' } }
   297        expectResult: *documents
   298    expectEvents:
   299      - client: *client
   300        eventType: command
   301        events:
   302          - commandStartedEvent:
   303              command:
   304                find: *collection
   305                batchSize: 1
   306                comment: { hello: 'find' }
   307                $db: *db
   308                lsid: { $$exists: true }
   309              commandName: find
   310          - commandStartedEvent:
   311              command:
   312                getMore: { $$type: [int, long] }
   313                collection: *collection
   314                comment: { hello: 'getMore' }
   315                $db: *db
   316                lsid: { $$exists: true }
   317              commandName: getMore
   318
   319  # Tailable cursor
   320  - description: does not close the cursor when receiving an empty batch
   321    runOnRequirements:
   322      - serverless: forbid
   323    operations:
   324      - name: dropCollection
   325        object: *db
   326        arguments:
   327          collection: &cappedCollection cappedCollection
   328      - name: createCollection
   329        object: *db
   330        arguments:
   331          collection: *cappedCollection
   332          capped: true
   333          size: 4096
   334          max: 3
   335        saveResultAsEntity: *cappedCollection
   336      - name: insertMany
   337        object: *cappedCollection
   338        arguments:
   339          documents:
   340            - { _id: 1, x: 11 }
   341            - { _id: 2, x: 22 }
   342      - name: createCommandCursor
   343        object: *db
   344        arguments:
   345          cursorType: tailable
   346          commandName: find
   347          batchSize: 2
   348          command: { find: *cappedCollection, tailable: true }
   349        saveResultAsEntity: &cursor cursor
   350      - name: iterateOnce
   351        object: *cursor
   352      - name: iterateOnce
   353        object: *cursor
   354      - name: iterateOnce
   355        object: *cursor
   356      - name: close
   357        object: *cursor
   358    expectEvents:
   359      - client: *client
   360        eventType: command
   361        events:
   362          - commandStartedEvent:
   363              command:
   364                drop: *cappedCollection
   365              commandName: drop
   366          - commandStartedEvent:
   367              command:
   368                create: *cappedCollection
   369              commandName: create
   370          - commandStartedEvent:
   371              command:
   372                insert: *cappedCollection
   373              commandName: insert
   374          - commandStartedEvent:
   375              command:
   376                find: *cappedCollection
   377                $db: *db
   378                lsid: { $$exists: true }
   379              commandName: find
   380          - commandStartedEvent:
   381              command:
   382                getMore: { $$type: [int, long] }
   383                collection: *cappedCollection
   384                $db: *db
   385                lsid: { $$exists: true }
   386              commandName: getMore
   387          - commandStartedEvent:
   388              command:
   389                killCursors: *cappedCollection
   390                cursors: { $$type: array }
   391              commandName: killCursors

View as plain text