# Tests in this file are generated from backpressure-retry-loop.yml.template.

description: tests that operations respect overload backoff retry loop

schemaVersion: '1.3'

runOnRequirements:
  - minServerVersion: '4.4' # failCommand
    topologies: [replicaset, sharded, load-balanced]

createEntities:
  - client:
      id: &client client
      useMultipleMongoses: false
      observeEvents: [commandStartedEvent, commandSucceededEvent, commandFailedEvent]
      ignoreCommandMonitoringEvents: [killCursors]

  - client:
      id: &internal_client internal_client
      useMultipleMongoses: false

  - database:
      id: &internal_db internal_db
      client: *internal_client
      databaseName: &database_name retryable-writes-tests

  - collection:
      id: &internal_collection retryable-writes-tests
      database: *internal_db
      collectionName: &collection_name coll

  - database:
      id: &database database
      client: *client
      databaseName: *database_name

  - collection:
      id: &collection collection
      database: *database
      collectionName: *collection_name

  - client:
      id: &client_retryReads_false client_retryReads_false
      useMultipleMongoses: false
      observeEvents: [commandStartedEvent, commandSucceededEvent, commandFailedEvent]
      ignoreCommandMonitoringEvents: [killCursors]
      uriOptions:
        retryReads: false

  - database:
      id: &database_retryReads_false database_retryReads_false
      client: *client_retryReads_false
      databaseName: *database_name

  - collection:
      id: &collection_retryReads_false collection_retryReads_false
      database: *database_retryReads_false
      collectionName: *collection_name

  - client:
      id: &client_retryWrites_false client_retryWrites_false
      useMultipleMongoses: false
      observeEvents: [commandStartedEvent, commandSucceededEvent, commandFailedEvent]
      ignoreCommandMonitoringEvents: [killCursors]
      uriOptions:
        retryWrites: false

  - database:
      id: &database_retryWrites_false database_retryWrites_false
      client: *client_retryWrites_false
      databaseName: *database_name

  - collection:
      id: &collection_retryWrites_false collection_retryWrites_false
      database: *database_retryWrites_false
      collectionName: *collection_name

initialData:
- collectionName: *collection_name
  databaseName: *database_name
  documents: []

_yamlAnchors:
  bulWriteInsertNamespace: &client_bulk_write_ns retryable-writes-tests.coll

tests: 
  - description: 'client.listDatabases retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [listDatabases]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: listDatabases
        object: *client
        arguments:
          filter: {}

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: listDatabases
          - commandFailedEvent:
              commandName: listDatabases
          - commandStartedEvent:
              commandName: listDatabases
          - commandFailedEvent:
              commandName: listDatabases
          - commandStartedEvent:
              commandName: listDatabases
          - commandSucceededEvent:
              commandName: listDatabases
  - description: 'client.listDatabases (read) does not retry if retryReads=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [listDatabases]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: listDatabases
        object: *client_retryReads_false
        arguments:
          filter: {}
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryReads_false
        events:
          - commandStartedEvent:
              commandName: listDatabases
          - commandFailedEvent:
              commandName: listDatabases


  - description: 'client.listDatabaseNames retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [listDatabases]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: listDatabaseNames
        object: *client

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: listDatabases
          - commandFailedEvent:
              commandName: listDatabases
          - commandStartedEvent:
              commandName: listDatabases
          - commandFailedEvent:
              commandName: listDatabases
          - commandStartedEvent:
              commandName: listDatabases
          - commandSucceededEvent:
              commandName: listDatabases
  - description: 'client.listDatabaseNames (read) does not retry if retryReads=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [listDatabases]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: listDatabaseNames
        object: *client_retryReads_false
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryReads_false
        events:
          - commandStartedEvent:
              commandName: listDatabases
          - commandFailedEvent:
              commandName: listDatabases


  - description: 'client.createChangeStream retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [aggregate]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: createChangeStream
        object: *client
        arguments:
          pipeline: []

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: aggregate
          - commandFailedEvent:
              commandName: aggregate
          - commandStartedEvent:
              commandName: aggregate
          - commandFailedEvent:
              commandName: aggregate
          - commandStartedEvent:
              commandName: aggregate
          - commandSucceededEvent:
              commandName: aggregate
  - description: 'client.createChangeStream (read) does not retry if retryReads=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [aggregate]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: createChangeStream
        object: *client_retryReads_false
        arguments:
          pipeline: []
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryReads_false
        events:
          - commandStartedEvent:
              commandName: aggregate
          - commandFailedEvent:
              commandName: aggregate


  - description: 'client.clientBulkWrite retries using operation loop'
    runOnRequirements:
      - minServerVersion: '8.0' # client bulk write added to server in 8.0
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [bulkWrite]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: clientBulkWrite
        object: *client
        arguments:
          models:
          - insertOne:
              namespace: *client_bulk_write_ns
              document: { _id: 8, x: 88 }

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: bulkWrite
          - commandFailedEvent:
              commandName: bulkWrite
          - commandStartedEvent:
              commandName: bulkWrite
          - commandFailedEvent:
              commandName: bulkWrite
          - commandStartedEvent:
              commandName: bulkWrite
          - commandSucceededEvent:
              commandName: bulkWrite
  - description: 'client.clientBulkWrite (write) does not retry if retryWrites=false'
    runOnRequirements:
      - minServerVersion: '8.0' # client bulk write added to server in 8.0
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [bulkWrite]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: clientBulkWrite
        object: *client_retryWrites_false
        arguments:
          models:
          - insertOne:
              namespace: *client_bulk_write_ns
              document: { _id: 8, x: 88 }
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryWrites_false
        events:
          - commandStartedEvent:
              commandName: bulkWrite
          - commandFailedEvent:
              commandName: bulkWrite


  - description: 'database.aggregate read retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [aggregate]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: aggregate
        object: *database
        arguments:
          pipeline: [ { $listLocalSessions: {} }, { $limit: 1 } ]

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: aggregate
          - commandFailedEvent:
              commandName: aggregate
          - commandStartedEvent:
              commandName: aggregate
          - commandFailedEvent:
              commandName: aggregate
          - commandStartedEvent:
              commandName: aggregate
          - commandSucceededEvent:
              commandName: aggregate
  - description: 'database.aggregate (read) does not retry if retryReads=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [aggregate]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: aggregate
        object: *database_retryReads_false
        arguments:
          pipeline: [ { $listLocalSessions: {} }, { $limit: 1 } ]
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryReads_false
        events:
          - commandStartedEvent:
              commandName: aggregate
          - commandFailedEvent:
              commandName: aggregate


  - description: 'database.listCollections retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [listCollections]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: listCollections
        object: *database
        arguments:
          filter: {}

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: listCollections
          - commandFailedEvent:
              commandName: listCollections
          - commandStartedEvent:
              commandName: listCollections
          - commandFailedEvent:
              commandName: listCollections
          - commandStartedEvent:
              commandName: listCollections
          - commandSucceededEvent:
              commandName: listCollections
  - description: 'database.listCollections (read) does not retry if retryReads=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [listCollections]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: listCollections
        object: *database_retryReads_false
        arguments:
          filter: {}
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryReads_false
        events:
          - commandStartedEvent:
              commandName: listCollections
          - commandFailedEvent:
              commandName: listCollections


  - description: 'database.listCollectionNames retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [listCollections]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: listCollectionNames
        object: *database
        arguments:
          filter: {}

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: listCollections
          - commandFailedEvent:
              commandName: listCollections
          - commandStartedEvent:
              commandName: listCollections
          - commandFailedEvent:
              commandName: listCollections
          - commandStartedEvent:
              commandName: listCollections
          - commandSucceededEvent:
              commandName: listCollections
  - description: 'database.listCollectionNames (read) does not retry if retryReads=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [listCollections]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: listCollectionNames
        object: *database_retryReads_false
        arguments:
          filter: {}
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryReads_false
        events:
          - commandStartedEvent:
              commandName: listCollections
          - commandFailedEvent:
              commandName: listCollections


  - description: 'database.runCommand retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [ping]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: runCommand
        object: *database
        arguments:
          command: { ping: 1 }
          commandName: ping

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: ping
          - commandFailedEvent:
              commandName: ping
          - commandStartedEvent:
              commandName: ping
          - commandFailedEvent:
              commandName: ping
          - commandStartedEvent:
              commandName: ping
          - commandSucceededEvent:
              commandName: ping
  - description: 'database.runCommand (read) does not retry if retryReads=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [ping]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: runCommand
        object: *database_retryReads_false
        arguments:
          command: { ping: 1 }
          commandName: ping
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryReads_false
        events:
          - commandStartedEvent:
              commandName: ping
          - commandFailedEvent:
              commandName: ping
  - description: 'database.runCommand (write) does not retry if retryWrites=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [ping]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: runCommand
        object: *database_retryWrites_false
        arguments:
          command: { ping: 1 }
          commandName: ping
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryWrites_false
        events:
          - commandStartedEvent:
              commandName: ping
          - commandFailedEvent:
              commandName: ping


  - description: 'database.createChangeStream retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [aggregate]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: createChangeStream
        object: *database
        arguments:
          pipeline: []

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: aggregate
          - commandFailedEvent:
              commandName: aggregate
          - commandStartedEvent:
              commandName: aggregate
          - commandFailedEvent:
              commandName: aggregate
          - commandStartedEvent:
              commandName: aggregate
          - commandSucceededEvent:
              commandName: aggregate
  - description: 'database.createChangeStream (read) does not retry if retryReads=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [aggregate]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: createChangeStream
        object: *database_retryReads_false
        arguments:
          pipeline: []
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryReads_false
        events:
          - commandStartedEvent:
              commandName: aggregate
          - commandFailedEvent:
              commandName: aggregate


  - description: 'collection.aggregate read retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [aggregate]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: aggregate
        object: *collection
        arguments:
          pipeline: []

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: aggregate
          - commandFailedEvent:
              commandName: aggregate
          - commandStartedEvent:
              commandName: aggregate
          - commandFailedEvent:
              commandName: aggregate
          - commandStartedEvent:
              commandName: aggregate
          - commandSucceededEvent:
              commandName: aggregate
  - description: 'collection.aggregate (read) does not retry if retryReads=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [aggregate]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: aggregate
        object: *collection_retryReads_false
        arguments:
          pipeline: []
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryReads_false
        events:
          - commandStartedEvent:
              commandName: aggregate
          - commandFailedEvent:
              commandName: aggregate


  - description: 'collection.countDocuments retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [aggregate]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: countDocuments
        object: *collection
        arguments:
          filter: {}

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: aggregate
          - commandFailedEvent:
              commandName: aggregate
          - commandStartedEvent:
              commandName: aggregate
          - commandFailedEvent:
              commandName: aggregate
          - commandStartedEvent:
              commandName: aggregate
          - commandSucceededEvent:
              commandName: aggregate
  - description: 'collection.countDocuments (read) does not retry if retryReads=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [aggregate]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: countDocuments
        object: *collection_retryReads_false
        arguments:
          filter: {}
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryReads_false
        events:
          - commandStartedEvent:
              commandName: aggregate
          - commandFailedEvent:
              commandName: aggregate


  - description: 'collection.estimatedDocumentCount retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [count]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: estimatedDocumentCount
        object: *collection

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: count
          - commandFailedEvent:
              commandName: count
          - commandStartedEvent:
              commandName: count
          - commandFailedEvent:
              commandName: count
          - commandStartedEvent:
              commandName: count
          - commandSucceededEvent:
              commandName: count
  - description: 'collection.estimatedDocumentCount (read) does not retry if retryReads=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [count]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: estimatedDocumentCount
        object: *collection_retryReads_false
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryReads_false
        events:
          - commandStartedEvent:
              commandName: count
          - commandFailedEvent:
              commandName: count


  - description: 'collection.distinct retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [distinct]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: distinct
        object: *collection
        arguments:
          fieldName: x
          filter: {}

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: distinct
          - commandFailedEvent:
              commandName: distinct
          - commandStartedEvent:
              commandName: distinct
          - commandFailedEvent:
              commandName: distinct
          - commandStartedEvent:
              commandName: distinct
          - commandSucceededEvent:
              commandName: distinct
  - description: 'collection.distinct (read) does not retry if retryReads=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [distinct]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: distinct
        object: *collection_retryReads_false
        arguments:
          fieldName: x
          filter: {}
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryReads_false
        events:
          - commandStartedEvent:
              commandName: distinct
          - commandFailedEvent:
              commandName: distinct


  - description: 'collection.find retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [find]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: find
        object: *collection
        arguments:
          filter: {}

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: find
          - commandFailedEvent:
              commandName: find
          - commandStartedEvent:
              commandName: find
          - commandFailedEvent:
              commandName: find
          - commandStartedEvent:
              commandName: find
          - commandSucceededEvent:
              commandName: find
  - description: 'collection.find (read) does not retry if retryReads=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [find]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: find
        object: *collection_retryReads_false
        arguments:
          filter: {}
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryReads_false
        events:
          - commandStartedEvent:
              commandName: find
          - commandFailedEvent:
              commandName: find


  - description: 'collection.findOne retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [find]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: findOne
        object: *collection
        arguments:
          filter: {}

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: find
          - commandFailedEvent:
              commandName: find
          - commandStartedEvent:
              commandName: find
          - commandFailedEvent:
              commandName: find
          - commandStartedEvent:
              commandName: find
          - commandSucceededEvent:
              commandName: find
  - description: 'collection.findOne (read) does not retry if retryReads=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [find]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: findOne
        object: *collection_retryReads_false
        arguments:
          filter: {}
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryReads_false
        events:
          - commandStartedEvent:
              commandName: find
          - commandFailedEvent:
              commandName: find


  - description: 'collection.listIndexes retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [listIndexes]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: listIndexes
        object: *collection

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: listIndexes
          - commandFailedEvent:
              commandName: listIndexes
          - commandStartedEvent:
              commandName: listIndexes
          - commandFailedEvent:
              commandName: listIndexes
          - commandStartedEvent:
              commandName: listIndexes
          - commandSucceededEvent:
              commandName: listIndexes
  - description: 'collection.listIndexes (read) does not retry if retryReads=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [listIndexes]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: listIndexes
        object: *collection_retryReads_false
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryReads_false
        events:
          - commandStartedEvent:
              commandName: listIndexes
          - commandFailedEvent:
              commandName: listIndexes


  - description: 'collection.listIndexNames retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [listIndexes]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: listIndexNames
        object: *collection

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: listIndexes
          - commandFailedEvent:
              commandName: listIndexes
          - commandStartedEvent:
              commandName: listIndexes
          - commandFailedEvent:
              commandName: listIndexes
          - commandStartedEvent:
              commandName: listIndexes
          - commandSucceededEvent:
              commandName: listIndexes
  - description: 'collection.listIndexNames (read) does not retry if retryReads=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [listIndexes]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: listIndexNames
        object: *collection_retryReads_false
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryReads_false
        events:
          - commandStartedEvent:
              commandName: listIndexes
          - commandFailedEvent:
              commandName: listIndexes


  - description: 'collection.createChangeStream retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [aggregate]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: createChangeStream
        object: *collection
        arguments:
          pipeline: []

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: aggregate
          - commandFailedEvent:
              commandName: aggregate
          - commandStartedEvent:
              commandName: aggregate
          - commandFailedEvent:
              commandName: aggregate
          - commandStartedEvent:
              commandName: aggregate
          - commandSucceededEvent:
              commandName: aggregate
  - description: 'collection.createChangeStream (read) does not retry if retryReads=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [aggregate]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: createChangeStream
        object: *collection_retryReads_false
        arguments:
          pipeline: []
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryReads_false
        events:
          - commandStartedEvent:
              commandName: aggregate
          - commandFailedEvent:
              commandName: aggregate


  - description: 'collection.insertOne retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [insert]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: insertOne
        object: *collection
        arguments:
          document: { _id: 2, x: 22 }

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: insert
          - commandFailedEvent:
              commandName: insert
          - commandStartedEvent:
              commandName: insert
          - commandFailedEvent:
              commandName: insert
          - commandStartedEvent:
              commandName: insert
          - commandSucceededEvent:
              commandName: insert
  - description: 'collection.insertOne (write) does not retry if retryWrites=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [insert]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: insertOne
        object: *collection_retryWrites_false
        arguments:
          document: { _id: 2, x: 22 }
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryWrites_false
        events:
          - commandStartedEvent:
              commandName: insert
          - commandFailedEvent:
              commandName: insert


  - description: 'collection.insertMany retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [insert]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: insertMany
        object: *collection
        arguments:
          documents:
            - { _id: 2, x: 22 }

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: insert
          - commandFailedEvent:
              commandName: insert
          - commandStartedEvent:
              commandName: insert
          - commandFailedEvent:
              commandName: insert
          - commandStartedEvent:
              commandName: insert
          - commandSucceededEvent:
              commandName: insert
  - description: 'collection.insertMany (write) does not retry if retryWrites=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [insert]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: insertMany
        object: *collection_retryWrites_false
        arguments:
          documents:
            - { _id: 2, x: 22 }
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryWrites_false
        events:
          - commandStartedEvent:
              commandName: insert
          - commandFailedEvent:
              commandName: insert


  - description: 'collection.deleteOne retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [delete]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: deleteOne
        object: *collection
        arguments:
          filter: {}

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: delete
          - commandFailedEvent:
              commandName: delete
          - commandStartedEvent:
              commandName: delete
          - commandFailedEvent:
              commandName: delete
          - commandStartedEvent:
              commandName: delete
          - commandSucceededEvent:
              commandName: delete
  - description: 'collection.deleteOne (write) does not retry if retryWrites=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [delete]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: deleteOne
        object: *collection_retryWrites_false
        arguments:
          filter: {}
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryWrites_false
        events:
          - commandStartedEvent:
              commandName: delete
          - commandFailedEvent:
              commandName: delete


  - description: 'collection.deleteMany retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [delete]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: deleteMany
        object: *collection
        arguments:
          filter: {}

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: delete
          - commandFailedEvent:
              commandName: delete
          - commandStartedEvent:
              commandName: delete
          - commandFailedEvent:
              commandName: delete
          - commandStartedEvent:
              commandName: delete
          - commandSucceededEvent:
              commandName: delete
  - description: 'collection.deleteMany (write) does not retry if retryWrites=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [delete]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: deleteMany
        object: *collection_retryWrites_false
        arguments:
          filter: {}
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryWrites_false
        events:
          - commandStartedEvent:
              commandName: delete
          - commandFailedEvent:
              commandName: delete


  - description: 'collection.replaceOne retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [update]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: replaceOne
        object: *collection
        arguments:
          filter: {}
          replacement: { x: 22 }

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: update
          - commandFailedEvent:
              commandName: update
          - commandStartedEvent:
              commandName: update
          - commandFailedEvent:
              commandName: update
          - commandStartedEvent:
              commandName: update
          - commandSucceededEvent:
              commandName: update
  - description: 'collection.replaceOne (write) does not retry if retryWrites=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [update]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: replaceOne
        object: *collection_retryWrites_false
        arguments:
          filter: {}
          replacement: { x: 22 }
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryWrites_false
        events:
          - commandStartedEvent:
              commandName: update
          - commandFailedEvent:
              commandName: update


  - description: 'collection.updateOne retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [update]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: updateOne
        object: *collection
        arguments:
          filter: {}
          update: { $set: { x: 22 } }

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: update
          - commandFailedEvent:
              commandName: update
          - commandStartedEvent:
              commandName: update
          - commandFailedEvent:
              commandName: update
          - commandStartedEvent:
              commandName: update
          - commandSucceededEvent:
              commandName: update
  - description: 'collection.updateOne (write) does not retry if retryWrites=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [update]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: updateOne
        object: *collection_retryWrites_false
        arguments:
          filter: {}
          update: { $set: { x: 22 } }
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryWrites_false
        events:
          - commandStartedEvent:
              commandName: update
          - commandFailedEvent:
              commandName: update


  - description: 'collection.updateMany retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [update]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: updateMany
        object: *collection
        arguments:
          filter: {}
          update: { $set: { x: 22 } }

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: update
          - commandFailedEvent:
              commandName: update
          - commandStartedEvent:
              commandName: update
          - commandFailedEvent:
              commandName: update
          - commandStartedEvent:
              commandName: update
          - commandSucceededEvent:
              commandName: update
  - description: 'collection.updateMany (write) does not retry if retryWrites=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [update]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: updateMany
        object: *collection_retryWrites_false
        arguments:
          filter: {}
          update: { $set: { x: 22 } }
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryWrites_false
        events:
          - commandStartedEvent:
              commandName: update
          - commandFailedEvent:
              commandName: update


  - description: 'collection.findOneAndDelete retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [findAndModify]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: findOneAndDelete
        object: *collection
        arguments:
          filter: {}

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: findAndModify
          - commandFailedEvent:
              commandName: findAndModify
          - commandStartedEvent:
              commandName: findAndModify
          - commandFailedEvent:
              commandName: findAndModify
          - commandStartedEvent:
              commandName: findAndModify
          - commandSucceededEvent:
              commandName: findAndModify
  - description: 'collection.findOneAndDelete (write) does not retry if retryWrites=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [findAndModify]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: findOneAndDelete
        object: *collection_retryWrites_false
        arguments:
          filter: {}
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryWrites_false
        events:
          - commandStartedEvent:
              commandName: findAndModify
          - commandFailedEvent:
              commandName: findAndModify


  - description: 'collection.findOneAndReplace retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [findAndModify]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: findOneAndReplace
        object: *collection
        arguments:
          filter: {}
          replacement: { x: 22 }

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: findAndModify
          - commandFailedEvent:
              commandName: findAndModify
          - commandStartedEvent:
              commandName: findAndModify
          - commandFailedEvent:
              commandName: findAndModify
          - commandStartedEvent:
              commandName: findAndModify
          - commandSucceededEvent:
              commandName: findAndModify
  - description: 'collection.findOneAndReplace (write) does not retry if retryWrites=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [findAndModify]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: findOneAndReplace
        object: *collection_retryWrites_false
        arguments:
          filter: {}
          replacement: { x: 22 }
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryWrites_false
        events:
          - commandStartedEvent:
              commandName: findAndModify
          - commandFailedEvent:
              commandName: findAndModify


  - description: 'collection.findOneAndUpdate retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [findAndModify]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: findOneAndUpdate
        object: *collection
        arguments:
          filter: {}
          update: { $set: { x: 22 } }

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: findAndModify
          - commandFailedEvent:
              commandName: findAndModify
          - commandStartedEvent:
              commandName: findAndModify
          - commandFailedEvent:
              commandName: findAndModify
          - commandStartedEvent:
              commandName: findAndModify
          - commandSucceededEvent:
              commandName: findAndModify
  - description: 'collection.findOneAndUpdate (write) does not retry if retryWrites=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [findAndModify]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: findOneAndUpdate
        object: *collection_retryWrites_false
        arguments:
          filter: {}
          update: { $set: { x: 22 } }
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryWrites_false
        events:
          - commandStartedEvent:
              commandName: findAndModify
          - commandFailedEvent:
              commandName: findAndModify


  - description: 'collection.bulkWrite retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [insert]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: bulkWrite
        object: *collection
        arguments:
          requests:
            - insertOne:
                document: { _id: 2, x: 22 }

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: insert
          - commandFailedEvent:
              commandName: insert
          - commandStartedEvent:
              commandName: insert
          - commandFailedEvent:
              commandName: insert
          - commandStartedEvent:
              commandName: insert
          - commandSucceededEvent:
              commandName: insert
  - description: 'collection.bulkWrite (write) does not retry if retryWrites=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [insert]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: bulkWrite
        object: *collection_retryWrites_false
        arguments:
          requests:
            - insertOne:
                document: { _id: 2, x: 22 }
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryWrites_false
        events:
          - commandStartedEvent:
              commandName: insert
          - commandFailedEvent:
              commandName: insert


  - description: 'collection.createIndex retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [createIndexes]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: createIndex
        object: *collection
        arguments:
          keys: { x: 11 }
          name: "x_11"

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: createIndexes
          - commandFailedEvent:
              commandName: createIndexes
          - commandStartedEvent:
              commandName: createIndexes
          - commandFailedEvent:
              commandName: createIndexes
          - commandStartedEvent:
              commandName: createIndexes
          - commandSucceededEvent:
              commandName: createIndexes
  - description: 'collection.createIndex (write) does not retry if retryWrites=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [createIndexes]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: createIndex
        object: *collection_retryWrites_false
        arguments:
          keys: { x: 11 }
          name: "x_11"
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryWrites_false
        events:
          - commandStartedEvent:
              commandName: createIndexes
          - commandFailedEvent:
              commandName: createIndexes


  - description: 'collection.dropIndex retries using operation loop'
    operations:
      - name: createIndex
        object: *internal_collection
        arguments:
          keys: { x: 11 }
          name: "x_11"
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [dropIndexes]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: dropIndex
        object: *collection
        arguments:
          name: "x_11"

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: dropIndexes
          - commandFailedEvent:
              commandName: dropIndexes
          - commandStartedEvent:
              commandName: dropIndexes
          - commandFailedEvent:
              commandName: dropIndexes
          - commandStartedEvent:
              commandName: dropIndexes
          - commandSucceededEvent:
              commandName: dropIndexes
  - description: 'collection.dropIndex (write) does not retry if retryWrites=false'
    operations:
      - name: createIndex
        object: *internal_collection
        arguments:
          keys: { x: 11 }
          name: "x_11"
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [dropIndexes]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: dropIndex
        object: *collection_retryWrites_false
        arguments:
          name: "x_11"
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryWrites_false
        events:
          - commandStartedEvent:
              commandName: dropIndexes
          - commandFailedEvent:
              commandName: dropIndexes


  - description: 'collection.dropIndexes retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [dropIndexes]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: dropIndexes
        object: *collection

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: dropIndexes
          - commandFailedEvent:
              commandName: dropIndexes
          - commandStartedEvent:
              commandName: dropIndexes
          - commandFailedEvent:
              commandName: dropIndexes
          - commandStartedEvent:
              commandName: dropIndexes
          - commandSucceededEvent:
              commandName: dropIndexes
  - description: 'collection.dropIndexes (write) does not retry if retryWrites=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [dropIndexes]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: dropIndexes
        object: *collection_retryWrites_false
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryWrites_false
        events:
          - commandStartedEvent:
              commandName: dropIndexes
          - commandFailedEvent:
              commandName: dropIndexes


  - description: 'collection.aggregate write retries using operation loop'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 2 }
            data:
              failCommands: [aggregate]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: aggregate
        object: *collection
        arguments:
          pipeline: [{$out: "output"}]

    expectEvents:
      - client: *client
        events:
          - commandStartedEvent:
              commandName: aggregate
          - commandFailedEvent:
              commandName: aggregate
          - commandStartedEvent:
              commandName: aggregate
          - commandFailedEvent:
              commandName: aggregate
          - commandStartedEvent:
              commandName: aggregate
          - commandSucceededEvent:
              commandName: aggregate
  - description: 'collection.aggregate (write) does not retry if retryWrites=false'
    operations:
      - name: failPoint
        object: testRunner
        arguments:
          client: *internal_client
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [aggregate]
              errorLabels: [RetryableError, SystemOverloadedError]
              errorCode: 2

      - name: aggregate
        object: *collection_retryWrites_false
        arguments:
          pipeline: [{$out: "output"}]
        expectError:
          isError: true
          isClientError: false

    expectEvents:
      - client: *client_retryWrites_false
        events:
          - commandStartedEvent:
              commandName: aggregate
          - commandFailedEvent:
              commandName: aggregate

