# Autogenerated tests that transient errors in a transaction unpin the session.
# See mongos-pin-auto-tests.py

description: mongos-pin-auto

schemaVersion: '1.4'

runOnRequirements:
  - minServerVersion: "4.1.8"
    # Note: tests utilize targetedFailPoint, which is incompatible with
    # load-balanced and useMultipleMongoses:true
    topologies: [ sharded ]
    # serverless proxy doesn't append error labels to errors in transactions
    # caused by failpoints (CLOUDP-88216)
    serverless: "forbid"

createEntities:
  - client:
      id: &client0 client0
      useMultipleMongoses: true
      observeEvents: [ commandStartedEvent ]
  - database:
      id: &database0 database0
      client: *client0
      databaseName: &database_name transaction-tests
  - collection:
      id: &collection0 collection0
      database: *database0
      collectionName: &collection_name test
  - session:
      id: &session0 session0
      client: *client0

initialData:
  - collectionName: *collection_name
    databaseName: *database_name
    documents: &data
      - { _id: 1 }
      - { _id: 2 }

tests:
  - description: remain pinned after non-transient Interrupted error on insertOne
    operations:
      - &startTransaction
        object: session0
        name: startTransaction
      - &initialCommand
        object: *collection0
        name: insertOne
        arguments:
          session: *session0
          document: { _id: 3 }
        expectResult: { $$unsetOrMatches: { insertedId: { $$unsetOrMatches: 3 } } }
      - object: testRunner
        name: targetedFailPoint
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [ "insert" ]
              errorCode: 11601
      - object: *collection0
        name: insertOne
        arguments:
          session: *session0
          document: { _id: 4 }
        expectError:
          errorLabelsOmit: ["TransientTransactionError", "UnknownTransactionCommitResult"]
          errorCodeName: Interrupted
      - &assertSessionPinned
        object: testRunner
        name: assertSessionPinned
        arguments:
          session: *session0
      - &commitTransaction
        object: *session0
        name: commitTransaction
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                insert: *collection_name
                documents:
                  - { _id: 3 }
                ordered: true
                readConcern: { $$exists: false }
                lsid: { $$sessionLsid: *session0 }
                txnNumber: { $numberLong: '1' }
                startTransaction: true
                autocommit: false
                writeConcern: { $$exists: false }
              commandName: insert
              databaseName: *database_name
          - commandStartedEvent:
              command:
                insert: *collection_name
                documents:
                  - { _id: 4 }
                ordered: true
                readConcern: { $$exists: false }
                lsid: { $$sessionLsid: *session0 }
                txnNumber: { $numberLong: '1' }
                startTransaction: { $$exists: false }
                autocommit: false
                writeConcern: { $$exists: false }
              commandName: insert
              databaseName: *database_name
          - commandStartedEvent:
              command:
                commitTransaction: 1
                lsid: { $$sessionLsid: *session0 }
                txnNumber: { $numberLong: '1' }
                startTransaction: { $$exists: false }
                autocommit: false
                writeConcern: { $$exists: false }
                recoveryToken: { $$exists: true }
              commandName: commitTransaction
              databaseName: admin
    outcome:
      - collectionName: *collection_name
        databaseName: *database_name
        documents:
          - { _id: 1 }
          - { _id: 2 }
          - { _id: 3 }

  - description: 'unpin after transient error within a transaction'
    operations:
      - *startTransaction
      - *initialCommand
      - object: testRunner
        name: targetedFailPoint
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: { times: 1 }
            data:
              failCommands: [ "insert" ]
              closeConnection: true
      - object: *collection0
        name: insertOne
        arguments:
          session: *session0
          document: { _id: 4 }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
          errorLabelsOmit: ["UnknownTransactionCommitResult"]
      - &assertSessionUnpinned
        object: testRunner
        name: assertSessionUnpinned
        arguments:
          session: *session0
      - &abortTransaction
        object: *session0
        name: abortTransaction
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                insert: *collection_name
                documents:
                  - { _id: 3 }
                ordered: true
                readConcern: { $$exists: false }
                lsid: { $$sessionLsid: *session0 }
                txnNumber: { $numberLong: '1' }
                startTransaction: true
                autocommit: false
                writeConcern: { $$exists: false }
              commandName: insert
              databaseName: *database_name
          - commandStartedEvent:
              command:
                insert: *collection_name
                documents:
                  - { _id: 4 }
                ordered: true
                readConcern: { $$exists: false }
                lsid: { $$sessionLsid: *session0 }
                txnNumber: { $numberLong: '1' }
                startTransaction: { $$exists: false }
                autocommit: false
                writeConcern: { $$exists: false }
              commandName: insert
              databaseName: *database_name
          - commandStartedEvent:
              command:
                abortTransaction: 1
                lsid: { $$sessionLsid: *session0 }
                txnNumber: { $numberLong: '1' }
                startTransaction: { $$exists: false }
                autocommit: false
                writeConcern: { $$exists: false }
                recoveryToken: { $$exists: true }
              commandName: abortTransaction
              databaseName: admin
    outcome: &outcome
      - collectionName: *collection_name
        databaseName: *database_name
        documents: *data

  # The rest of the tests in this file test every operation type against
  # multiple types of transient errors (connection and error code).

  - description: remain pinned after non-transient Interrupted error on insertOne insert
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["insert"]
              errorCode: 11601
      - name: insertOne
        object: *collection0
        arguments:
          session: *session0
          document: { _id: 4 }
        expectError:
          errorLabelsOmit: ["TransientTransactionError"]
      - *assertSessionPinned
      - *abortTransaction
    outcome: *outcome

  - description: remain pinned after non-transient Interrupted error on insertMany insert
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["insert"]
              errorCode: 11601
      - name: insertMany
        object: *collection0
        arguments:
          session: *session0
          documents: [ { _id: 4 }, { _id: 5 } ]
        expectError:
          errorLabelsOmit: ["TransientTransactionError"]
      - *assertSessionPinned
      - *abortTransaction
    outcome: *outcome

  - description: remain pinned after non-transient Interrupted error on updateOne update
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["update"]
              errorCode: 11601
      - name: updateOne
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: 1 }
          update: { $inc: { x: 1 } }
        expectError:
          errorLabelsOmit: ["TransientTransactionError"]
      - *assertSessionPinned
      - *abortTransaction
    outcome: *outcome

  - description: remain pinned after non-transient Interrupted error on replaceOne update
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["update"]
              errorCode: 11601
      - name: replaceOne
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: 1 }
          replacement: { y: 1 }
        expectError:
          errorLabelsOmit: ["TransientTransactionError"]
      - *assertSessionPinned
      - *abortTransaction
    outcome: *outcome

  - description: remain pinned after non-transient Interrupted error on updateMany update
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["update"]
              errorCode: 11601
      - name: updateMany
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: { $gte: 1 } }
          update: {$set: { z: 1 } }
        expectError:
          errorLabelsOmit: ["TransientTransactionError"]
      - *assertSessionPinned
      - *abortTransaction
    outcome: *outcome

  - description: remain pinned after non-transient Interrupted error on deleteOne delete
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["delete"]
              errorCode: 11601
      - name: deleteOne
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: 1 }
        expectError:
          errorLabelsOmit: ["TransientTransactionError"]
      - *assertSessionPinned
      - *abortTransaction
    outcome: *outcome

  - description: remain pinned after non-transient Interrupted error on deleteMany delete
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["delete"]
              errorCode: 11601
      - name: deleteMany
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: { $gte: 1 } }
        expectError:
          errorLabelsOmit: ["TransientTransactionError"]
      - *assertSessionPinned
      - *abortTransaction
    outcome: *outcome

  - description: remain pinned after non-transient Interrupted error on findOneAndDelete findAndModify
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["findAndModify"]
              errorCode: 11601
      - name: findOneAndDelete
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: 1 }
        expectError:
          errorLabelsOmit: ["TransientTransactionError"]
      - *assertSessionPinned
      - *abortTransaction
    outcome: *outcome

  - description: remain pinned after non-transient Interrupted error on findOneAndUpdate findAndModify
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["findAndModify"]
              errorCode: 11601
      - name: findOneAndUpdate
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: 1 }
          update: { $inc: { x: 1 } }
          returnDocument: Before
        expectError:
          errorLabelsOmit: ["TransientTransactionError"]
      - *assertSessionPinned
      - *abortTransaction
    outcome: *outcome

  - description: remain pinned after non-transient Interrupted error on findOneAndReplace findAndModify
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["findAndModify"]
              errorCode: 11601
      - name: findOneAndReplace
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: 1 }
          replacement: { y: 1 }
          returnDocument: Before
        expectError:
          errorLabelsOmit: ["TransientTransactionError"]
      - *assertSessionPinned
      - *abortTransaction
    outcome: *outcome

  - description: remain pinned after non-transient Interrupted error on bulkWrite insert
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["insert"]
              errorCode: 11601
      - name: bulkWrite
        object: *collection0
        arguments:
          session: *session0
          requests:
            - insertOne:
                document: { _id: 1 }
        expectError:
          errorLabelsOmit: ["TransientTransactionError"]
      - *assertSessionPinned
      - *abortTransaction
    outcome: *outcome

  - description: remain pinned after non-transient Interrupted error on bulkWrite update
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["update"]
              errorCode: 11601
      - name: bulkWrite
        object: *collection0
        arguments:
          session: *session0
          requests:
            - updateOne:
                filter: { _id: 1 }
                update: { $set: { x: 1 } }
        expectError:
          errorLabelsOmit: ["TransientTransactionError"]
      - *assertSessionPinned
      - *abortTransaction
    outcome: *outcome

  - description: remain pinned after non-transient Interrupted error on bulkWrite delete
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["delete"]
              errorCode: 11601
      - name: bulkWrite
        object: *collection0
        arguments:
          session: *session0
          requests:
            - deleteOne:
                filter: { _id: 1 }
        expectError:
          errorLabelsOmit: ["TransientTransactionError"]
      - *assertSessionPinned
      - *abortTransaction
    outcome: *outcome

  - description: remain pinned after non-transient Interrupted error on find find
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["find"]
              errorCode: 11601
      - name: find
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: 1 }
        expectError:
          errorLabelsOmit: ["TransientTransactionError"]
      - *assertSessionPinned
      - *abortTransaction
    outcome: *outcome

  - description: remain pinned after non-transient Interrupted error on countDocuments aggregate
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["aggregate"]
              errorCode: 11601
      - name: countDocuments
        object: *collection0
        arguments:
          session: *session0
          filter: {}
        expectError:
          errorLabelsOmit: ["TransientTransactionError"]
      - *assertSessionPinned
      - *abortTransaction
    outcome: *outcome

  - description: remain pinned after non-transient Interrupted error on aggregate aggregate
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["aggregate"]
              errorCode: 11601
      - name: aggregate
        object: *collection0
        arguments:
          session: *session0
          pipeline: []
        expectError:
          errorLabelsOmit: ["TransientTransactionError"]
      - *assertSessionPinned
      - *abortTransaction
    outcome: *outcome

  - description: remain pinned after non-transient Interrupted error on distinct distinct
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["distinct"]
              errorCode: 11601
      - name: distinct
        object: *collection0
        arguments:
          session: *session0
          fieldName: _id
          filter: {}
        expectError:
          errorLabelsOmit: ["TransientTransactionError"]
      - *assertSessionPinned
      - *abortTransaction
    outcome: *outcome

  - description: remain pinned after non-transient Interrupted error on runCommand insert
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["insert"]
              errorCode: 11601
      - name: runCommand
        object: *database0
        arguments:
          session: *session0
          commandName: insert
          command:
            insert: *collection_name
            documents:
              - { _id : 1 }
        expectError:
          errorLabelsOmit: ["TransientTransactionError"]
      - *assertSessionPinned
      - *abortTransaction
    outcome: *outcome

  - description: remain pinned after non-transient Interrupted error on clientBulkWrite bulkWrite
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["bulkWrite"]
              errorCode: 11601
      - name: clientBulkWrite
        object: *client0
        arguments:
          session: *session0
          models:
          - insertOne:
              namespace: database0.collection0
              document: { _id: 8, x: 88 }
        expectError:
          errorLabelsOmit: ["TransientTransactionError"]
      - *assertSessionPinned
      - *abortTransaction
    outcome: *outcome
    runOnRequirements:
      - minServerVersion: "8.0" # `bulkWrite` added to server 8.0"

  - description: unpin after transient connection error on insertOne insert
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["insert"]
              closeConnection: true
      - name: insertOne
        object: *collection0
        arguments:
          session: *session0
          document: { _id: 4 }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient ShutdownInProgress error on insertOne insert
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["insert"]
              errorCode: 91
      - name: insertOne
        object: *collection0
        arguments:
          session: *session0
          document: { _id: 4 }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient connection error on insertMany insert
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["insert"]
              closeConnection: true
      - name: insertMany
        object: *collection0
        arguments:
          session: *session0
          documents: [ { _id: 4 }, { _id: 5 } ]
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient ShutdownInProgress error on insertMany insert
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["insert"]
              errorCode: 91
      - name: insertMany
        object: *collection0
        arguments:
          session: *session0
          documents: [ { _id: 4 }, { _id: 5 } ]
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient connection error on updateOne update
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["update"]
              closeConnection: true
      - name: updateOne
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: 1 }
          update: { $inc: { x: 1 } }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient ShutdownInProgress error on updateOne update
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["update"]
              errorCode: 91
      - name: updateOne
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: 1 }
          update: { $inc: { x: 1 } }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient connection error on replaceOne update
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["update"]
              closeConnection: true
      - name: replaceOne
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: 1 }
          replacement: { y: 1 }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient ShutdownInProgress error on replaceOne update
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["update"]
              errorCode: 91
      - name: replaceOne
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: 1 }
          replacement: { y: 1 }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient connection error on updateMany update
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["update"]
              closeConnection: true
      - name: updateMany
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: { $gte: 1 } }
          update: {$set: { z: 1 } }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient ShutdownInProgress error on updateMany update
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["update"]
              errorCode: 91
      - name: updateMany
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: { $gte: 1 } }
          update: {$set: { z: 1 } }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient connection error on deleteOne delete
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["delete"]
              closeConnection: true
      - name: deleteOne
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: 1 }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient ShutdownInProgress error on deleteOne delete
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["delete"]
              errorCode: 91
      - name: deleteOne
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: 1 }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient connection error on deleteMany delete
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["delete"]
              closeConnection: true
      - name: deleteMany
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: { $gte: 1 } }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient ShutdownInProgress error on deleteMany delete
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["delete"]
              errorCode: 91
      - name: deleteMany
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: { $gte: 1 } }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient connection error on findOneAndDelete findAndModify
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["findAndModify"]
              closeConnection: true
      - name: findOneAndDelete
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: 1 }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient ShutdownInProgress error on findOneAndDelete findAndModify
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["findAndModify"]
              errorCode: 91
      - name: findOneAndDelete
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: 1 }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient connection error on findOneAndUpdate findAndModify
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["findAndModify"]
              closeConnection: true
      - name: findOneAndUpdate
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: 1 }
          update: { $inc: { x: 1 } }
          returnDocument: Before
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient ShutdownInProgress error on findOneAndUpdate findAndModify
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["findAndModify"]
              errorCode: 91
      - name: findOneAndUpdate
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: 1 }
          update: { $inc: { x: 1 } }
          returnDocument: Before
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient connection error on findOneAndReplace findAndModify
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["findAndModify"]
              closeConnection: true
      - name: findOneAndReplace
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: 1 }
          replacement: { y: 1 }
          returnDocument: Before
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient ShutdownInProgress error on findOneAndReplace findAndModify
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["findAndModify"]
              errorCode: 91
      - name: findOneAndReplace
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: 1 }
          replacement: { y: 1 }
          returnDocument: Before
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient connection error on bulkWrite insert
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["insert"]
              closeConnection: true
      - name: bulkWrite
        object: *collection0
        arguments:
          session: *session0
          requests:
            - insertOne:
                document: { _id: 1 }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient ShutdownInProgress error on bulkWrite insert
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["insert"]
              errorCode: 91
      - name: bulkWrite
        object: *collection0
        arguments:
          session: *session0
          requests:
            - insertOne:
                document: { _id: 1 }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient connection error on bulkWrite update
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["update"]
              closeConnection: true
      - name: bulkWrite
        object: *collection0
        arguments:
          session: *session0
          requests:
            - updateOne:
                filter: { _id: 1 }
                update: { $set: { x: 1 } }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient ShutdownInProgress error on bulkWrite update
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["update"]
              errorCode: 91
      - name: bulkWrite
        object: *collection0
        arguments:
          session: *session0
          requests:
            - updateOne:
                filter: { _id: 1 }
                update: { $set: { x: 1 } }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient connection error on bulkWrite delete
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["delete"]
              closeConnection: true
      - name: bulkWrite
        object: *collection0
        arguments:
          session: *session0
          requests:
            - deleteOne:
                filter: { _id: 1 }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient ShutdownInProgress error on bulkWrite delete
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["delete"]
              errorCode: 91
      - name: bulkWrite
        object: *collection0
        arguments:
          session: *session0
          requests:
            - deleteOne:
                filter: { _id: 1 }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient connection error on find find
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["find"]
              closeConnection: true
      - name: find
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: 1 }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient ShutdownInProgress error on find find
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["find"]
              errorCode: 91
      - name: find
        object: *collection0
        arguments:
          session: *session0
          filter: { _id: 1 }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient connection error on countDocuments aggregate
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["aggregate"]
              closeConnection: true
      - name: countDocuments
        object: *collection0
        arguments:
          session: *session0
          filter: {}
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient ShutdownInProgress error on countDocuments aggregate
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["aggregate"]
              errorCode: 91
      - name: countDocuments
        object: *collection0
        arguments:
          session: *session0
          filter: {}
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient connection error on aggregate aggregate
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["aggregate"]
              closeConnection: true
      - name: aggregate
        object: *collection0
        arguments:
          session: *session0
          pipeline: []
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient ShutdownInProgress error on aggregate aggregate
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["aggregate"]
              errorCode: 91
      - name: aggregate
        object: *collection0
        arguments:
          session: *session0
          pipeline: []
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient connection error on distinct distinct
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["distinct"]
              closeConnection: true
      - name: distinct
        object: *collection0
        arguments:
          session: *session0
          fieldName: _id
          filter: {}
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient ShutdownInProgress error on distinct distinct
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["distinct"]
              errorCode: 91
      - name: distinct
        object: *collection0
        arguments:
          session: *session0
          fieldName: _id
          filter: {}
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient connection error on runCommand insert
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["insert"]
              closeConnection: true
      - name: runCommand
        object: *database0
        arguments:
          session: *session0
          commandName: insert
          command:
            insert: *collection_name
            documents:
              - { _id : 1 }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient ShutdownInProgress error on runCommand insert
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["insert"]
              errorCode: 91
      - name: runCommand
        object: *database0
        arguments:
          session: *session0
          commandName: insert
          command:
            insert: *collection_name
            documents:
              - { _id : 1 }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome

  - description: unpin after transient connection error on clientBulkWrite bulkWrite
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["bulkWrite"]
              closeConnection: true
      - name: clientBulkWrite
        object: *client0
        arguments:
          session: *session0
          models:
          - insertOne:
              namespace: database0.collection0
              document: { _id: 8, x: 88 }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome
    runOnRequirements:
      - minServerVersion: "8.0" # `bulkWrite` added to server 8.0"

  - description: unpin after transient ShutdownInProgress error on clientBulkWrite bulkWrite
    operations:
      - *startTransaction
      - *initialCommand
      - name: targetedFailPoint
        object: testRunner
        arguments:
          session: *session0
          failPoint:
            configureFailPoint: failCommand
            mode: {times: 1}
            data:
              failCommands: ["bulkWrite"]
              errorCode: 91
      - name: clientBulkWrite
        object: *client0
        arguments:
          session: *session0
          models:
          - insertOne:
              namespace: database0.collection0
              document: { _id: 8, x: 88 }
        expectError:
          errorLabelsContain: ["TransientTransactionError"]
      - *assertSessionUnpinned
      - *abortTransaction
    outcome: *outcome
    runOnRequirements:
      - minServerVersion: "8.0" # `bulkWrite` added to server 8.0"
