description: backpressure-retryable-commit
schemaVersion: "1.4"
runOnRequirements:
  - minServerVersion: "4.4"
    topologies:
      - sharded
      - replicaset
      - load-balanced
createEntities:
  -
    client:
      id: &client0 client0
      useMultipleMongoses: false
      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: []
tests:
  - description: commitTransaction retries if backpressure labels are added
    runOnRequirements:
      - serverless: forbid
    operations:
      - object: testRunner
        name: failPoint
        arguments:
          client: *client0
          failPoint:
            configureFailPoint: failCommand
            mode:
              times: 2
            data:
              failCommands:
                - commitTransaction
              errorLabels:
                - RetryableError
                - SystemOverloadedError
              errorCode: 112
      - object: *session0
        name: startTransaction
      - object: *collection0
        name: insertOne
        arguments:
          session: *session0
          document:
            _id: 1
        expectResult:
          $$unsetOrMatches:
            insertedId:
              $$unsetOrMatches: 1
      - object: *session0
        name: commitTransaction
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                insert: test
                documents:
                  - _id: 1
                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:
                commitTransaction: 1
                lsid:
                  $$sessionLsid: *session0
                txnNumber:
                  $numberLong: "1"
                startTransaction:
                  $$exists: false
                autocommit: false
                writeConcern:
                  $$exists: false
              commandName: commitTransaction
              databaseName: admin
          - commandStartedEvent:
              command:
                commitTransaction: 1
                lsid:
                  $$sessionLsid: *session0
                txnNumber:
                  $numberLong: "1"
                startTransaction:
                  $$exists: false
                autocommit: false
                writeConcern:
                  $$exists: false
              commandName: commitTransaction
              databaseName: admin
          - commandStartedEvent:
              command:
                commitTransaction: 1
                lsid:
                  $$sessionLsid: *session0
                txnNumber:
                  $numberLong: "1"
                startTransaction:
                  $$exists: false
                autocommit: false
                writeConcern:
                  $$exists: false
              commandName: commitTransaction
              databaseName: admin
    outcome:
      - collectionName: *collection_name
        databaseName: *database_name
        documents:
          - _id: 1
  - description: commitTransaction is retried maxAttempts=2 times if backpressure labels are added
    runOnRequirements:
      - serverless: forbid
    operations:
      - object: testRunner
        name: failPoint
        arguments:
          client: *client0
          failPoint:
            configureFailPoint: failCommand
            mode: alwaysOn
            data:
              failCommands:
                - commitTransaction
              errorLabels:
                - RetryableError
                - SystemOverloadedError
              errorCode: 112
      - object: *session0
        name: startTransaction
      - object: *collection0
        name: insertOne
        arguments:
          session: *session0
          document:
            _id: 1
        expectResult:
          $$unsetOrMatches:
            insertedId:
              $$unsetOrMatches: 1
      - object: *session0
        name: commitTransaction
        expectError:
          isError: true
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                insert: test
                documents:
                  - _id: 1
                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:
                commitTransaction: 1
                lsid:
                  $$sessionLsid: *session0
                txnNumber:
                  $numberLong: "1"
                startTransaction:
                  $$exists: false
                autocommit: false
                writeConcern:
                  $$exists: false
              commandName: commitTransaction
              databaseName: admin
          - commandStartedEvent:
              commandName: commitTransaction
          - commandStartedEvent:
              commandName: commitTransaction
    outcome:
      - collectionName: *collection_name
        databaseName: *database_name
        documents: []
