runOn:
    -
        minServerVersion: "4.0"
        topology: ["replicaset"]
    -
        minServerVersion: "4.1.8"
        topology: ["sharded"]

database_name: &database_name "transaction-tests"
collection_name: &collection_name "test"

data: []

tests:
  - description: DuplicateKey errors do not contain transient label

    operations:
      - name: startTransaction
        object: session0
      - name: insertMany
        object: collection
        arguments:
          session: session0
          documents:
            - _id: 1
            - _id: 1
        result:
          errorLabelsOmit: ["TransientTransactionError", "UnknownTransactionCommitResult"]
          # DuplicateKey error code included in the bulk write error message
          # returned by the server
          errorContains: E11000
      - name: abortTransaction
        object: session0

    expectations:
      - command_started_event:
          command:
            insert: *collection_name
            documents:
              - _id: 1
              - _id: 1
            ordered: true
            readConcern:
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction: true
            autocommit: false
            writeConcern:
          command_name: insert
          database_name: *database_name
      - command_started_event:
          command:
            abortTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            writeConcern:
          command_name: abortTransaction
          database_name: admin

    outcome:
      collection:
        data: []

  - description: NotMaster errors contain transient label

    failPoint:
      configureFailPoint: failCommand
      mode: { times: 1 }
      data:
          failCommands: ["insert"]
          errorCode: 10107  # NotMaster

    operations:
      - name: startTransaction
        object: session0
      - name: insertOne
        object: collection
        arguments:
          session: session0
          document:
            _id: 1
        result:
          # Note, the server will return the errorLabel in this case.
          errorLabelsContain: ["TransientTransactionError"]
          errorLabelsOmit: ["RetryableWriteError", "UnknownTransactionCommitResult"]
      - name: abortTransaction
        object: session0

    expectations:
      - command_started_event:
          command:
            insert: *collection_name
            documents:
              - _id: 1
            ordered: true
            readConcern:
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction: true
            autocommit: false
            writeConcern:
          command_name: insert
          database_name: *database_name
      - command_started_event:
          command:
            abortTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            writeConcern:
          command_name: abortTransaction
          database_name: admin

    outcome:
      collection:
        data: []

  - description: WriteConflict errors contain transient label

    failPoint:
      configureFailPoint: failCommand
      mode: { times: 1 }
      data:
          failCommands: ["insert"]
          errorCode: 112  # WriteConflict

    operations:
      - name: startTransaction
        object: session0
      - name: insertOne
        object: collection
        arguments:
          session: session0
          document:
            _id: 1
        result:
          # Note, the server will return the errorLabel in this case.
          errorLabelsContain: ["TransientTransactionError"]
          errorLabelsOmit: ["RetryableWriteError", "UnknownTransactionCommitResult"]
      - name: abortTransaction
        object: session0

    expectations:
      - command_started_event:
          command:
            insert: *collection_name
            documents:
              - _id: 1
            ordered: true
            readConcern:
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction: true
            autocommit: false
            writeConcern:
          command_name: insert
          database_name: *database_name
      - command_started_event:
          command:
            abortTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            writeConcern:
          command_name: abortTransaction
          database_name: admin

    outcome:
      collection:
        data: []

  - description: NoSuchTransaction errors contain transient label

    failPoint:
      configureFailPoint: failCommand
      mode: { times: 1 }
      data:
          failCommands: ["insert"]
          errorCode: 251  # NoSuchTransaction

    operations:
      - name: startTransaction
        object: session0
      - name: insertOne
        object: collection
        arguments:
          session: session0
          document:
            _id: 1
        result:
          # Note, the server will return the errorLabel in this case.
          errorLabelsContain: ["TransientTransactionError"]
          errorLabelsOmit: ["RetryableWriteError", "UnknownTransactionCommitResult"]
      - name: abortTransaction
        object: session0

    expectations:
      - command_started_event:
          command:
            insert: *collection_name
            documents:
              - _id: 1
            ordered: true
            readConcern:
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction: true
            autocommit: false
            writeConcern:
          command_name: insert
          database_name: *database_name
      - command_started_event:
          command:
            abortTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            writeConcern:
          command_name: abortTransaction
          database_name: admin

    outcome:
      collection:
        data: []

  - description: NoSuchTransaction errors on commit contain transient label

    failPoint:
      configureFailPoint: failCommand
      mode: { times: 1 }
      data:
          failCommands: ["commitTransaction"]
          errorCode: 251  # NoSuchTransaction

    operations:
      - name: startTransaction
        object: session0
      - name: insertOne
        object: collection
        arguments:
          session: session0
          document:
            _id: 1
        result:
          insertedId: 1
      - name: commitTransaction
        object: session0
        result:
          # Note, the server will return the errorLabel in this case.
          errorLabelsContain: ["TransientTransactionError"]
          errorLabelsOmit: ["RetryableWriteError", "UnknownTransactionCommitResult"]

    expectations:
      - command_started_event:
          command:
            insert: *collection_name
            documents:
              - _id: 1
            ordered: true
            readConcern:
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction: true
            autocommit: false
            writeConcern:
          command_name: insert
          database_name: *database_name
      - command_started_event:
          command:
            commitTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            writeConcern:
          command_name: commitTransaction
          database_name: admin

    outcome:
      collection:
        data: []

  - description: add TransientTransactionError label to connection errors, but do not add RetryableWriteError label

    failPoint:
      configureFailPoint: failCommand
      mode: { times: 4 }
      data:
          failCommands: ["insert", "find", "aggregate", "distinct"]
          closeConnection: true

    operations:
      - name: startTransaction
        object: session0
      - name: insertOne
        object: collection
        arguments:
          session: session0
          document:
            _id: 1
        result: &transient_label_only
          errorLabelsContain: ["TransientTransactionError"]
          # While a connection error would normally be retryable, these are not because
          # they occur within a transaction; ensure the driver does not add the
          # RetryableWriteError label to these errors.
          errorLabelsOmit: ["RetryableWriteError", "UnknownTransactionCommitResult"]
      - name: find
        object: collection
        arguments:
          session: session0
        result: *transient_label_only
      - name: aggregate
        object: collection
        arguments:
          pipeline:
            - $project:
                _id: 1
          session: session0
        result: *transient_label_only
      - name: distinct
        object: collection
        arguments:
          fieldName: _id
          session: session0
        result: *transient_label_only
      - name: abortTransaction
        object: session0

    expectations:
      - command_started_event:
          command:
            insert: *collection_name
            documents:
              - _id: 1
            ordered: true
            readConcern:
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction: true
            autocommit: false
            writeConcern:
          command_name: insert
          database_name: *database_name
      - command_started_event:
          command:
            find: *collection_name
            readConcern:
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
          command_name: find
          database_name: *database_name
      - command_started_event:
          command:
            aggregate: *collection_name
            pipeline:
              - $project:
                  _id: 1
            cursor: {}
            readConcern:
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
          command_name: aggregate
          database_name: *database_name
      - command_started_event:
          command:
            distinct: *collection_name
            key: _id
            lsid: session0
            readConcern:
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
          command_name: distinct
          database_name: *database_name
      - command_started_event:
          command:
            abortTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            writeConcern:
          command_name: abortTransaction
          database_name: admin

    outcome:
      collection:
        data: []

  - description: add RetryableWriteError and UnknownTransactionCommitResult labels to connection errors

    failPoint:
      configureFailPoint: failCommand
      mode: { times: 2 }
      data:
          failCommands: ["commitTransaction"]
          closeConnection: true

    operations:
      - name: startTransaction
        object: session0
      - name: insertOne
        object: collection
        arguments:
          session: session0
          document:
            _id: 1
        result:
          insertedId: 1
      - name: commitTransaction
        object: session0
        result:
          errorLabelsContain: ["RetryableWriteError", "UnknownTransactionCommitResult"]
          errorLabelsOmit: ["TransientTransactionError"]
      - name: commitTransaction
        object: session0

    expectations:
      - command_started_event:
          command:
            insert: *collection_name
            documents:
              - _id: 1
            ordered: true
            readConcern:
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction: true
            autocommit: false
            writeConcern:
          command_name: insert
          database_name: *database_name
      - command_started_event:
          command:
            commitTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            writeConcern:
          command_name: commitTransaction
          database_name: admin
      - command_started_event:
          command:
            commitTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            # commitTransaction applies w:majority on retries
            writeConcern: { w: majority, wtimeout: 10000 }
          command_name: commitTransaction
          database_name: admin
      - command_started_event:
          command:
            commitTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            writeConcern: { w: majority, wtimeout: 10000 }
          command_name: commitTransaction
          database_name: admin

    outcome:
      collection:
        data:
          - _id: 1

  - description: add RetryableWriteError and UnknownTransactionCommitResult labels to retryable commit errors

    failPoint:
      configureFailPoint: failCommand
      mode: { times: 2 }
      data:
          failCommands: ["commitTransaction"]
          errorCode: 11602  # InterruptedDueToReplStateChange
          errorLabels: ["RetryableWriteError"]

    operations:
      - name: startTransaction
        object: session0
      - name: insertOne
        object: collection
        arguments:
          session: session0
          document:
            _id: 1
        result:
          insertedId: 1
      - name: commitTransaction
        object: session0
        result:
          errorLabelsContain: ["RetryableWriteError", "UnknownTransactionCommitResult"]
          errorLabelsOmit: ["TransientTransactionError"]
      - name: commitTransaction
        object: session0

    expectations:
      - command_started_event:
          command:
            insert: *collection_name
            documents:
              - _id: 1
            ordered: true
            readConcern:
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction: true
            autocommit: false
            writeConcern:
          command_name: insert
          database_name: *database_name
      - command_started_event:
          command:
            commitTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            writeConcern:
          command_name: commitTransaction
          database_name: admin
      - command_started_event:
          command:
            commitTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            # commitTransaction applies w:majority on retries
            writeConcern: { w: majority, wtimeout: 10000 }
          command_name: commitTransaction
          database_name: admin
      - command_started_event:
          command:
            commitTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            writeConcern: { w: majority, wtimeout: 10000 }
          command_name: commitTransaction
          database_name: admin

    outcome:
      collection:
        data:
          - _id: 1

  - description: add RetryableWriteError and UnknownTransactionCommitResult labels to writeConcernError ShutdownInProgress

    failPoint:
      configureFailPoint: failCommand
      mode: { times: 2 }
      data:
          failCommands: ["commitTransaction"]
          writeConcernError:
            code: 91
            errmsg: Replication is being shut down
            errorLabels: ["RetryableWriteError"]

    operations:
      - name: startTransaction
        object: session0
        arguments:
          options:
            writeConcern:
              w: majority
      - name: insertOne
        object: collection
        arguments:
          session: session0
          document:
            _id: 1
        result:
          insertedId: 1
      - name: commitTransaction
        object: session0
        result:
          errorLabelsContain: ["RetryableWriteError", "UnknownTransactionCommitResult"]
          errorLabelsOmit: ["TransientTransactionError"]
      - name: commitTransaction
        object: session0

    expectations:
      - command_started_event:
          command:
            insert: *collection_name
            documents:
              - _id: 1
            ordered: true
            readConcern:
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction: true
            autocommit: false
            writeConcern:
          command_name: insert
          database_name: *database_name
      - command_started_event:
          command:
            commitTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            writeConcern:
              w: majority
          command_name: commitTransaction
          database_name: admin
      - command_started_event:
          command:
            commitTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            # commitTransaction applies w:majority on retries
            writeConcern: { w: majority, wtimeout: 10000 }
          command_name: commitTransaction
          database_name: admin
      - command_started_event:
          command:
            commitTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            # commitTransaction applies w:majority on retries
            writeConcern: { w: majority, wtimeout: 10000 }
          command_name: commitTransaction
          database_name: admin

    outcome:
      collection:
        data:
          - _id: 1

  - description: do not add RetryableWriteError label to writeConcernError ShutdownInProgress that occurs within transaction

    failPoint:
      configureFailPoint: failCommand
      mode: { times: 1 }
      data:
          failCommands: ["insert"]
          writeConcernError:
            code: 91
            errmsg: Replication is being shut down

    operations:
      - name: startTransaction
        object: session0
        arguments:
          options:
            writeConcern:
              w: majority
      - name: insertOne
        object: collection
        arguments:
          session: session0
          document:
            _id: 1
        result:
          errorLabelsContain: []
          errorLabelsOmit: ["RetryableWriteError", "TransientTransactionError", "UnknownTransactionCommitResult"]
      - name: abortTransaction
        object: session0

    expectations:
      - command_started_event:
          command:
            insert: *collection_name
            documents:
              - _id: 1
            ordered: true
            readConcern:
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction: true
            autocommit: false
          command_name: insert
          database_name: *database_name
      - command_started_event:
          command:
            abortTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
          command_name: abortTransaction
          database_name: admin

    outcome:
      collection:
        data: []

  - description: add UnknownTransactionCommitResult label to writeConcernError WriteConcernFailed

    failPoint:
      configureFailPoint: failCommand
      mode: { times: 1 }
      data:
          failCommands: ["commitTransaction"]
          writeConcernError:
            code: 64  # WriteConcernFailed without wtimeout
            errmsg: multiple errors reported

    operations:
      - name: startTransaction
        object: session0
        arguments:
          options:
            writeConcern:
              w: majority
      - name: insertOne
        object: collection
        arguments:
          session: session0
          document:
            _id: 1
        result:
          insertedId: 1
      - name: commitTransaction
        object: session0
        result:
          errorLabelsContain: ["UnknownTransactionCommitResult"]
          errorLabelsOmit: ["RetryableWriteError", "TransientTransactionError"]
      - name: commitTransaction
        object: session0

    expectations:
      - command_started_event:
          command:
            insert: *collection_name
            documents:
              - _id: 1
            ordered: true
            readConcern:
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction: true
            autocommit: false
            writeConcern:
          command_name: insert
          database_name: *database_name
      - command_started_event:
          command:
            commitTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            writeConcern:
              w: majority
          command_name: commitTransaction
          database_name: admin
      - command_started_event:
          command:
            commitTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            # commitTransaction applies w:majority on retries
            writeConcern: { w: majority, wtimeout: 10000 }
          command_name: commitTransaction
          database_name: admin

    outcome:
      collection:
        data:
          - _id: 1

  - description: add UnknownTransactionCommitResult label to writeConcernError WriteConcernFailed with wtimeout

    failPoint:
      configureFailPoint: failCommand
      mode: { times: 1 }
      data:
          failCommands: ["commitTransaction"]
          writeConcernError:
            code: 64
            codeName: WriteConcernFailed
            errmsg: waiting for replication timed out
            errInfo: {wtimeout: True}

    operations:
      - name: startTransaction
        object: session0
        arguments:
          options:
            writeConcern:
              w: majority
      - name: insertOne
        object: collection
        arguments:
          session: session0
          document:
            _id: 1
        result:
          insertedId: 1
      - name: commitTransaction
        object: session0
        result:
          errorLabelsContain: ["UnknownTransactionCommitResult"]
          errorLabelsOmit: ["RetryableWriteError", "TransientTransactionError"]
      - name: commitTransaction
        object: session0

    expectations:
      - command_started_event:
          command:
            insert: *collection_name
            documents:
              - _id: 1
            ordered: true
            readConcern:
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction: true
            autocommit: false
            writeConcern:
          command_name: insert
          database_name: *database_name
      - command_started_event:
          command:
            commitTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            writeConcern:
              w: majority
          command_name: commitTransaction
          database_name: admin
      - command_started_event:
          command:
            commitTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            # commitTransaction applies w:majority on retries
            writeConcern: { w: majority, wtimeout: 10000 }
          command_name: commitTransaction
          database_name: admin

    outcome:
      collection:
        data:
          - _id: 1

  - description: omit UnknownTransactionCommitResult label from writeConcernError UnsatisfiableWriteConcern

    failPoint:
      configureFailPoint: failCommand
      mode: { times: 1 }
      data:
          failCommands: ["commitTransaction"]
          writeConcernError:
            code: 100  # UnsatisfiableWriteConcern
            errmsg: Not enough data-bearing nodes

    operations:
      - name: startTransaction
        object: session0
        arguments:
          options:
            writeConcern:
              w: majority
      - name: insertOne
        object: collection
        arguments:
          session: session0
          document:
            _id: 1
        result:
          insertedId: 1
      - name: commitTransaction
        object: session0
        result:
          errorLabelsOmit: ["RetryableWriteError", "TransientTransactionError", "UnknownTransactionCommitResult"]

    expectations:
      - command_started_event:
          command:
            insert: *collection_name
            documents:
              - _id: 1
            ordered: true
            readConcern:
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction: true
            autocommit: false
            writeConcern:
          command_name: insert
          database_name: *database_name
      - command_started_event:
          command:
            commitTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            writeConcern:
              w: majority
          command_name: commitTransaction
          database_name: admin

    outcome:
      collection:
        data:
          - _id: 1

  - description: omit UnknownTransactionCommitResult label from writeConcernError UnknownReplWriteConcern

    failPoint:
      configureFailPoint: failCommand
      mode: { times: 1 }
      data:
          failCommands: ["commitTransaction"]
          writeConcernError:
            code: 79  # UnknownReplWriteConcern
            errmsg: No write concern mode named 'blah' found in replica set configuration

    operations:
      - name: startTransaction
        object: session0
        arguments:
          options:
            writeConcern:
              w: majority
      - name: insertOne
        object: collection
        arguments:
          session: session0
          document:
            _id: 1
        result:
          insertedId: 1
      - name: commitTransaction
        object: session0
        result:
          errorLabelsOmit: ["RetryableWriteConcern", "TransientTransactionError", "UnknownTransactionCommitResult"]

    expectations:
      - command_started_event:
          command:
            insert: *collection_name
            documents:
              - _id: 1
            ordered: true
            readConcern:
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction: true
            autocommit: false
            writeConcern:
          command_name: insert
          database_name: *database_name
      - command_started_event:
          command:
            commitTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            writeConcern:
              w: majority
          command_name: commitTransaction
          database_name: admin

    outcome:
      collection:
        data:
          - _id: 1

  - description: do not add UnknownTransactionCommitResult label to MaxTimeMSExpired inside transactions

    failPoint:
      configureFailPoint: failCommand
      mode: { times: 1 }
      data:
        failCommands: ["aggregate"]
        errorCode: 50  # MaxTimeMSExpired

    operations:
      - name: startTransaction
        object: session0
      - name: insertOne
        object: collection
        arguments:
          session: session0
          document:
            _id: 1
        result:
          insertedId: 1
      - name: aggregate
        object: collection
        arguments:
          pipeline:
            - $project:
                _id: 1
          maxTimeMS: 60000
          session: session0
        result:
          errorLabelsOmit: ["RetryableWriteError", "UnknownTransactionCommitResult", "TransientTransactionError"]
      - name: abortTransaction
        object: session0

    expectations:
      - command_started_event:
          command:
            insert: *collection_name
            documents:
              - _id: 1
            ordered: true
            readConcern:
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction: true
            autocommit: false
            writeConcern:
          command_name: insert
          database_name: *database_name
      - command_started_event:
          command:
            aggregate: *collection_name
            pipeline:
              - $project:
                  _id: 1
            cursor: {}
            readConcern:
            lsid: session0
            txnNumber:
              $numberLong: "1"
            autocommit: false
            maxTimeMS: 60000
          command_name: aggregate
          database_name: *database_name
      - command_started_event:
          command:
            abortTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            writeConcern:
          command_name: abortTransaction
          database_name: admin

    outcome:
      collection:
        data: []

  - description: add UnknownTransactionCommitResult label to MaxTimeMSExpired

    failPoint:
      configureFailPoint: failCommand
      mode: { times: 1 }
      data:
          failCommands: ["commitTransaction"]
          errorCode: 50  # MaxTimeMSExpired

    operations:
      - name: startTransaction
        object: session0
        arguments:
          options:
            writeConcern:
              w: majority
            maxCommitTimeMS: 60000
      - name: insertOne
        object: collection
        arguments:
          session: session0
          document:
            _id: 1
        result:
          insertedId: 1
      - name: commitTransaction
        object: session0
        result:
          errorLabelsContain: ["UnknownTransactionCommitResult"]
          errorLabelsOmit: ["RetryableWriteError", "TransientTransactionError"]
      - name: commitTransaction
        object: session0

    expectations:
      - command_started_event:
          command:
            insert: *collection_name
            documents:
              - _id: 1
            ordered: true
            readConcern:
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction: true
            autocommit: false
            writeConcern:
          command_name: insert
          database_name: *database_name
      - command_started_event:
          command:
            commitTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            writeConcern:
              w: majority
            maxTimeMS: 60000
          command_name: commitTransaction
          database_name: admin
      - command_started_event:
          command:
            commitTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            # commitTransaction applies w:majority on retries
            writeConcern: { w: majority, wtimeout: 10000 }
            maxTimeMS: 60000
          command_name: commitTransaction
          database_name: admin

    outcome:
      collection:
        data:
          - _id: 1

  - description: add UnknownTransactionCommitResult label to writeConcernError MaxTimeMSExpired

    failPoint:
      configureFailPoint: failCommand
      mode: { times: 1 }
      data:
          failCommands: ["commitTransaction"]
          writeConcernError:
            code: 50  # MaxTimeMSExpired
            errmsg: operation exceeded time limit

    operations:
      - name: startTransaction
        object: session0
        arguments:
          options:
            writeConcern:
              w: majority
            maxCommitTimeMS: 60000
      - name: insertOne
        object: collection
        arguments:
          session: session0
          document:
            _id: 1
        result:
          insertedId: 1
      - name: commitTransaction
        object: session0
        result:
          errorLabelsContain: ["UnknownTransactionCommitResult"]
          errorLabelsOmit: ["RetryableWriteError", "TransientTransactionError"]
      - name: commitTransaction
        object: session0

    expectations:
      - command_started_event:
          command:
            insert: *collection_name
            documents:
              - _id: 1
            ordered: true
            readConcern:
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction: true
            autocommit: false
            writeConcern:
          command_name: insert
          database_name: *database_name
      - command_started_event:
          command:
            commitTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            writeConcern:
              w: majority
            maxTimeMS: 60000
          command_name: commitTransaction
          database_name: admin
      - command_started_event:
          command:
            commitTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            # commitTransaction applies w:majority on retries
            writeConcern: { w: majority, wtimeout: 10000 }
            maxTimeMS: 60000
          command_name: commitTransaction
          database_name: admin

    outcome:
      collection:
        data:
          - _id: 1
