{
  "runOn": [
    {
      "minServerVersion": "4.1.8",
      "topology": [
        "sharded"
      ]
    }
  ],
  "database_name": "transaction-tests",
  "collection_name": "test",
  "data": [
    {
      "_id": 1
    },
    {
      "_id": 2
    }
  ],
  "tests": [
    {
      "description": "countDocuments",
      "useMultipleMongoses": true,
      "operations": [
        {
          "name": "startTransaction",
          "object": "session0"
        },
        {
          "name": "countDocuments",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": 2
            },
            "session": "session0"
          },
          "result": 1
        },
        {
          "name": "countDocuments",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": 2
            },
            "session": "session0"
          },
          "result": 1
        },
        {
          "name": "countDocuments",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": 2
            },
            "session": "session0"
          },
          "result": 1
        },
        {
          "name": "countDocuments",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": 2
            },
            "session": "session0"
          },
          "result": 1
        },
        {
          "name": "countDocuments",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": 2
            },
            "session": "session0"
          },
          "result": 1
        },
        {
          "name": "countDocuments",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": 2
            },
            "session": "session0"
          },
          "result": 1
        },
        {
          "name": "countDocuments",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": 2
            },
            "session": "session0"
          },
          "result": 1
        },
        {
          "name": "countDocuments",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": 2
            },
            "session": "session0"
          },
          "result": 1
        },
        {
          "name": "commitTransaction",
          "object": "session0"
        }
      ],
      "outcome": {
        "collection": {
          "data": [
            {
              "_id": 1
            },
            {
              "_id": 2
            }
          ]
        }
      }
    },
    {
      "description": "distinct",
      "useMultipleMongoses": true,
      "operations": [
        {
          "name": "startTransaction",
          "object": "session0"
        },
        {
          "name": "distinct",
          "object": "collection",
          "arguments": {
            "fieldName": "_id",
            "session": "session0"
          },
          "result": [
            1,
            2
          ]
        },
        {
          "name": "distinct",
          "object": "collection",
          "arguments": {
            "fieldName": "_id",
            "session": "session0"
          },
          "result": [
            1,
            2
          ]
        },
        {
          "name": "distinct",
          "object": "collection",
          "arguments": {
            "fieldName": "_id",
            "session": "session0"
          },
          "result": [
            1,
            2
          ]
        },
        {
          "name": "distinct",
          "object": "collection",
          "arguments": {
            "fieldName": "_id",
            "session": "session0"
          },
          "result": [
            1,
            2
          ]
        },
        {
          "name": "distinct",
          "object": "collection",
          "arguments": {
            "fieldName": "_id",
            "session": "session0"
          },
          "result": [
            1,
            2
          ]
        },
        {
          "name": "distinct",
          "object": "collection",
          "arguments": {
            "fieldName": "_id",
            "session": "session0"
          },
          "result": [
            1,
            2
          ]
        },
        {
          "name": "distinct",
          "object": "collection",
          "arguments": {
            "fieldName": "_id",
            "session": "session0"
          },
          "result": [
            1,
            2
          ]
        },
        {
          "name": "distinct",
          "object": "collection",
          "arguments": {
            "fieldName": "_id",
            "session": "session0"
          },
          "result": [
            1,
            2
          ]
        },
        {
          "name": "commitTransaction",
          "object": "session0"
        }
      ],
      "outcome": {
        "collection": {
          "data": [
            {
              "_id": 1
            },
            {
              "_id": 2
            }
          ]
        }
      }
    },
    {
      "description": "find",
      "useMultipleMongoses": true,
      "operations": [
        {
          "name": "startTransaction",
          "object": "session0"
        },
        {
          "name": "find",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": 2
            },
            "session": "session0"
          },
          "result": [
            {
              "_id": 2
            }
          ]
        },
        {
          "name": "find",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": 2
            },
            "session": "session0"
          },
          "result": [
            {
              "_id": 2
            }
          ]
        },
        {
          "name": "find",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": 2
            },
            "session": "session0"
          },
          "result": [
            {
              "_id": 2
            }
          ]
        },
        {
          "name": "find",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": 2
            },
            "session": "session0"
          },
          "result": [
            {
              "_id": 2
            }
          ]
        },
        {
          "name": "find",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": 2
            },
            "session": "session0"
          },
          "result": [
            {
              "_id": 2
            }
          ]
        },
        {
          "name": "find",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": 2
            },
            "session": "session0"
          },
          "result": [
            {
              "_id": 2
            }
          ]
        },
        {
          "name": "find",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": 2
            },
            "session": "session0"
          },
          "result": [
            {
              "_id": 2
            }
          ]
        },
        {
          "name": "find",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": 2
            },
            "session": "session0"
          },
          "result": [
            {
              "_id": 2
            }
          ]
        },
        {
          "name": "commitTransaction",
          "object": "session0"
        }
      ],
      "outcome": {
        "collection": {
          "data": [
            {
              "_id": 1
            },
            {
              "_id": 2
            }
          ]
        }
      }
    },
    {
      "description": "insertOne",
      "useMultipleMongoses": true,
      "operations": [
        {
          "name": "startTransaction",
          "object": "session0"
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "document": {
              "_id": 3
            },
            "session": "session0"
          },
          "result": {
            "insertedId": 3
          }
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "document": {
              "_id": 4
            },
            "session": "session0"
          },
          "result": {
            "insertedId": 4
          }
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "document": {
              "_id": 5
            },
            "session": "session0"
          },
          "result": {
            "insertedId": 5
          }
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "document": {
              "_id": 6
            },
            "session": "session0"
          },
          "result": {
            "insertedId": 6
          }
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "document": {
              "_id": 7
            },
            "session": "session0"
          },
          "result": {
            "insertedId": 7
          }
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "document": {
              "_id": 8
            },
            "session": "session0"
          },
          "result": {
            "insertedId": 8
          }
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "document": {
              "_id": 9
            },
            "session": "session0"
          },
          "result": {
            "insertedId": 9
          }
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "document": {
              "_id": 10
            },
            "session": "session0"
          },
          "result": {
            "insertedId": 10
          }
        },
        {
          "name": "commitTransaction",
          "object": "session0"
        }
      ],
      "outcome": {
        "collection": {
          "data": [
            {
              "_id": 1
            },
            {
              "_id": 2
            },
            {
              "_id": 3
            },
            {
              "_id": 4
            },
            {
              "_id": 5
            },
            {
              "_id": 6
            },
            {
              "_id": 7
            },
            {
              "_id": 8
            },
            {
              "_id": 9
            },
            {
              "_id": 10
            }
          ]
        }
      }
    },
    {
      "description": "mixed read write operations",
      "useMultipleMongoses": true,
      "operations": [
        {
          "name": "startTransaction",
          "object": "session0"
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "document": {
              "_id": 3
            },
            "session": "session0"
          },
          "result": {
            "insertedId": 3
          }
        },
        {
          "name": "countDocuments",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": 3
            },
            "session": "session0"
          },
          "result": 1
        },
        {
          "name": "countDocuments",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": 3
            },
            "session": "session0"
          },
          "result": 1
        },
        {
          "name": "countDocuments",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": 3
            },
            "session": "session0"
          },
          "result": 1
        },
        {
          "name": "countDocuments",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": 3
            },
            "session": "session0"
          },
          "result": 1
        },
        {
          "name": "countDocuments",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": 3
            },
            "session": "session0"
          },
          "result": 1
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "document": {
              "_id": 4
            },
            "session": "session0"
          },
          "result": {
            "insertedId": 4
          }
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "document": {
              "_id": 5
            },
            "session": "session0"
          },
          "result": {
            "insertedId": 5
          }
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "document": {
              "_id": 6
            },
            "session": "session0"
          },
          "result": {
            "insertedId": 6
          }
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "document": {
              "_id": 7
            },
            "session": "session0"
          },
          "result": {
            "insertedId": 7
          }
        },
        {
          "name": "commitTransaction",
          "object": "session0"
        }
      ],
      "outcome": {
        "collection": {
          "data": [
            {
              "_id": 1
            },
            {
              "_id": 2
            },
            {
              "_id": 3
            },
            {
              "_id": 4
            },
            {
              "_id": 5
            },
            {
              "_id": 6
            },
            {
              "_id": 7
            }
          ]
        }
      }
    },
    {
      "description": "multiple commits",
      "useMultipleMongoses": true,
      "operations": [
        {
          "name": "startTransaction",
          "object": "session0"
        },
        {
          "name": "insertMany",
          "object": "collection",
          "arguments": {
            "documents": [
              {
                "_id": 3
              },
              {
                "_id": 4
              }
            ],
            "session": "session0"
          },
          "result": {
            "insertedIds": {
              "0": 3,
              "1": 4
            }
          }
        },
        {
          "name": "assertSessionPinned",
          "object": "testRunner",
          "arguments": {
            "session": "session0"
          }
        },
        {
          "name": "commitTransaction",
          "object": "session0"
        },
        {
          "name": "assertSessionPinned",
          "object": "testRunner",
          "arguments": {
            "session": "session0"
          }
        },
        {
          "name": "commitTransaction",
          "object": "session0"
        },
        {
          "name": "commitTransaction",
          "object": "session0"
        },
        {
          "name": "commitTransaction",
          "object": "session0"
        },
        {
          "name": "commitTransaction",
          "object": "session0"
        },
        {
          "name": "commitTransaction",
          "object": "session0"
        },
        {
          "name": "commitTransaction",
          "object": "session0"
        },
        {
          "name": "commitTransaction",
          "object": "session0"
        },
        {
          "name": "commitTransaction",
          "object": "session0"
        },
        {
          "name": "commitTransaction",
          "object": "session0"
        },
        {
          "name": "assertSessionPinned",
          "object": "testRunner",
          "arguments": {
            "session": "session0"
          }
        }
      ],
      "outcome": {
        "collection": {
          "data": [
            {
              "_id": 1
            },
            {
              "_id": 2
            },
            {
              "_id": 3
            },
            {
              "_id": 4
            }
          ]
        }
      }
    },
    {
      "description": "remain pinned after non-transient error on commit",
      "useMultipleMongoses": true,
      "operations": [
        {
          "name": "startTransaction",
          "object": "session0"
        },
        {
          "name": "insertMany",
          "object": "collection",
          "arguments": {
            "documents": [
              {
                "_id": 3
              },
              {
                "_id": 4
              }
            ],
            "session": "session0"
          },
          "result": {
            "insertedIds": {
              "0": 3,
              "1": 4
            }
          }
        },
        {
          "name": "assertSessionPinned",
          "object": "testRunner",
          "arguments": {
            "session": "session0"
          }
        },
        {
          "name": "targetedFailPoint",
          "object": "testRunner",
          "arguments": {
            "session": "session0",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 1
              },
              "data": {
                "failCommands": [
                  "commitTransaction"
                ],
                "errorCode": 51
              }
            }
          }
        },
        {
          "name": "commitTransaction",
          "object": "session0",
          "result": {
            "errorLabelsOmit": [
              "TransientTransactionError"
            ],
            "errorCode": 51
          }
        },
        {
          "name": "assertSessionPinned",
          "object": "testRunner",
          "arguments": {
            "session": "session0"
          }
        },
        {
          "name": "commitTransaction",
          "object": "session0"
        },
        {
          "name": "assertSessionPinned",
          "object": "testRunner",
          "arguments": {
            "session": "session0"
          }
        }
      ],
      "outcome": {
        "collection": {
          "data": [
            {
              "_id": 1
            },
            {
              "_id": 2
            },
            {
              "_id": 3
            },
            {
              "_id": 4
            }
          ]
        }
      }
    },
    {
      "description": "unpin after transient error within a transaction",
      "useMultipleMongoses": true,
      "operations": [
        {
          "name": "startTransaction",
          "object": "session0"
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "session": "session0",
            "document": {
              "_id": 3
            }
          },
          "result": {
            "insertedId": 3
          }
        },
        {
          "name": "targetedFailPoint",
          "object": "testRunner",
          "arguments": {
            "session": "session0",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 1
              },
              "data": {
                "failCommands": [
                  "insert"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "session": "session0",
            "document": {
              "_id": 4
            }
          },
          "result": {
            "errorLabelsContain": [
              "TransientTransactionError"
            ],
            "errorLabelsOmit": [
              "UnknownTransactionCommitResult"
            ]
          }
        },
        {
          "name": "abortTransaction",
          "object": "session0"
        }
      ],
      "expectations": [
        {
          "command_started_event": {
            "command": {
              "insert": "test",
              "documents": [
                {
                  "_id": 3
                }
              ],
              "ordered": true,
              "readConcern": null,
              "lsid": "session0",
              "txnNumber": {
                "$numberLong": "1"
              },
              "startTransaction": true,
              "autocommit": false,
              "writeConcern": null
            },
            "command_name": "insert",
            "database_name": "transaction-tests"
          }
        },
        {
          "command_started_event": {
            "command": {
              "insert": "test",
              "documents": [
                {
                  "_id": 4
                }
              ],
              "ordered": true,
              "readConcern": null,
              "lsid": "session0",
              "txnNumber": {
                "$numberLong": "1"
              },
              "startTransaction": null,
              "autocommit": false,
              "writeConcern": null
            },
            "command_name": "insert",
            "database_name": "transaction-tests"
          }
        },
        {
          "command_started_event": {
            "command": {
              "abortTransaction": 1,
              "lsid": "session0",
              "txnNumber": {
                "$numberLong": "1"
              },
              "startTransaction": null,
              "autocommit": false,
              "writeConcern": null,
              "recoveryToken": 42
            },
            "command_name": "abortTransaction",
            "database_name": "admin"
          }
        }
      ],
      "outcome": {
        "collection": {
          "data": [
            {
              "_id": 1
            },
            {
              "_id": 2
            }
          ]
        }
      }
    },
    {
      "description": "unpin after transient error within a transaction and commit",
      "useMultipleMongoses": true,
      "clientOptions": {
        "heartbeatFrequencyMS": 30000
      },
      "operations": [
        {
          "name": "startTransaction",
          "object": "session0"
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "session": "session0",
            "document": {
              "_id": 3
            }
          },
          "result": {
            "insertedId": 3
          }
        },
        {
          "name": "targetedFailPoint",
          "object": "testRunner",
          "arguments": {
            "session": "session0",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 7
              },
              "data": {
                "failCommands": [
                  "insert",
                  "isMaster"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "session": "session0",
            "document": {
              "_id": 4
            }
          },
          "result": {
            "errorLabelsContain": [
              "TransientTransactionError"
            ],
            "errorLabelsOmit": [
              "UnknownTransactionCommitResult"
            ]
          }
        },
        {
          "name": "commitTransaction",
          "object": "session0",
          "result": {
            "errorLabelsContain": [
              "TransientTransactionError"
            ],
            "errorLabelsOmit": [
              "UnknownTransactionCommitResult"
            ],
            "errorCodeName": "NoSuchTransaction"
          }
        }
      ],
      "expectations": [
        {
          "command_started_event": {
            "command": {
              "insert": "test",
              "documents": [
                {
                  "_id": 3
                }
              ],
              "ordered": true,
              "readConcern": null,
              "lsid": "session0",
              "txnNumber": {
                "$numberLong": "1"
              },
              "startTransaction": true,
              "autocommit": false,
              "writeConcern": null
            },
            "command_name": "insert",
            "database_name": "transaction-tests"
          }
        },
        {
          "command_started_event": {
            "command": {
              "insert": "test",
              "documents": [
                {
                  "_id": 4
                }
              ],
              "ordered": true,
              "readConcern": null,
              "lsid": "session0",
              "txnNumber": {
                "$numberLong": "1"
              },
              "startTransaction": null,
              "autocommit": false,
              "writeConcern": null
            },
            "command_name": "insert",
            "database_name": "transaction-tests"
          }
        },
        {
          "command_started_event": {
            "command": {
              "commitTransaction": 1,
              "lsid": "session0",
              "txnNumber": {
                "$numberLong": "1"
              },
              "startTransaction": null,
              "autocommit": false,
              "writeConcern": null,
              "recoveryToken": 42
            },
            "command_name": "commitTransaction",
            "database_name": "admin"
          }
        }
      ],
      "outcome": {
        "collection": {
          "data": [
            {
              "_id": 1
            },
            {
              "_id": 2
            }
          ]
        }
      }
    }
  ]
}
