description: backpressure-retryable-reads
schemaVersion: "1.3"
runOnRequirements:
  - minServerVersion: "4.4"
    topologies:
      - replicaset
      - sharded
      - 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: reads are retried if backpressure labels are added
    operations:
      - object: *session0
        name: startTransaction
      - object: *collection0
        name: insertOne
        arguments:
          session: *session0
          document:
            _id: 1
        expectResult:
          $$unsetOrMatches:
            insertedId:
              $$unsetOrMatches: 1
      - object: testRunner
        name: failPoint
        arguments:
          client: *client0
          failPoint:
            configureFailPoint: failCommand
            mode:
              times: 1
            data:
              failCommands:
                - find
              errorLabels:
                - RetryableError
                - SystemOverloadedError
              errorCode: 112
      - object: *collection0
        name: find
        arguments:
          filter: {}
          session: *session0
      - 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:
                find: test
                readConcern:
                  $$exists: false
                lsid:
                  $$sessionLsid: *session0
                txnNumber:
                  $numberLong: "1"
                autocommit: false
                writeConcern:
                  $$exists: false
              commandName: find
              databaseName: *database_name
          - commandStartedEvent:
              command:
                find: test
                readConcern:
                  $$exists: false
                lsid:
                  $$sessionLsid: *session0
                txnNumber:
                  $numberLong: "1"
                autocommit: false
                writeConcern:
                  $$exists: false
              commandName: find
              databaseName: *database_name
          - commandStartedEvent:
              command:
                abortTransaction:
                  $$exists: false
                lsid:
                  $$sessionLsid: *session0
                txnNumber:
                  $numberLong: "1"
                startTransaction:
                  $$exists: false
                autocommit: false
                writeConcern:
                  $$exists: false
              commandName: commitTransaction
              databaseName: admin
  - description: reads are retried maxAttempts=2 times if backpressure labels are added
    operations:
      - object: *session0
        name: startTransaction
      - object: *collection0
        name: insertOne
        arguments:
          session: *session0
          document:
            _id: 1
        expectResult:
          $$unsetOrMatches:
            insertedId:
              $$unsetOrMatches: 1
      - object: testRunner
        name: failPoint
        arguments:
          client: *client0
          failPoint:
            configureFailPoint: failCommand
            mode: alwaysOn
            data:
              failCommands:
                - find
              errorLabels:
                - RetryableError
                - SystemOverloadedError
              errorCode: 112
      - object: *collection0
        name: find
        arguments:
          filter: {}
          session: *session0
        expectError:
          isError: true
      - object: *session0
        name: abortTransaction
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              commandName: insert
          - commandStartedEvent:
              commandName: find
          - commandStartedEvent:
              commandName: find
          - commandStartedEvent:
              commandName: find
          - commandStartedEvent:
              commandName: abortTransaction
