{
  "runOn": [
    {
      "minServerVersion": "4.0",
      "topology": [
        "replicaset"
      ]
    },
    {
      "minServerVersion": "4.1.8",
      "topology": [
        "sharded"
      ]
    }
  ],
  "database_name": "transaction-tests",
  "collection_name": "test",
  "data": [],
  "tests": [
    {
      "description": "run command with default read preference",
      "operations": [
        {
          "name": "startTransaction",
          "object": "session0"
        },
        {
          "name": "runCommand",
          "object": "database",
          "command_name": "insert",
          "arguments": {
            "session": "session0",
            "command": {
              "insert": "test",
              "documents": [
                {
                  "_id": 1
                }
              ]
            }
          },
          "result": {
            "n": 1
          }
        },
        {
          "name": "commitTransaction",
          "object": "session0"
        }
      ],
      "expectations": [
        {
          "command_started_event": {
            "command": {
              "insert": "test",
              "documents": [
                {
                  "_id": 1
                }
              ],
              "readConcern": null,
              "lsid": "session0",
              "txnNumber": {
                "$numberLong": "1"
              },
              "startTransaction": true,
              "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
            },
            "command_name": "commitTransaction",
            "database_name": "admin"
          }
        }
      ]
    },
    {
      "description": "run command with secondary read preference in client option and primary read preference in transaction options",
      "clientOptions": {
        "readPreference": "secondary"
      },
      "operations": [
        {
          "name": "startTransaction",
          "object": "session0",
          "arguments": {
            "options": {
              "readPreference": {
                "mode": "Primary"
              }
            }
          }
        },
        {
          "name": "runCommand",
          "object": "database",
          "command_name": "insert",
          "arguments": {
            "session": "session0",
            "command": {
              "insert": "test",
              "documents": [
                {
                  "_id": 1
                }
              ]
            }
          },
          "result": {
            "n": 1
          }
        },
        {
          "name": "commitTransaction",
          "object": "session0"
        }
      ],
      "expectations": [
        {
          "command_started_event": {
            "command": {
              "insert": "test",
              "documents": [
                {
                  "_id": 1
                }
              ],
              "readConcern": null,
              "lsid": "session0",
              "txnNumber": {
                "$numberLong": "1"
              },
              "startTransaction": true,
              "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
            },
            "command_name": "commitTransaction",
            "database_name": "admin"
          }
        }
      ]
    },
    {
      "description": "run command with explicit primary read preference",
      "operations": [
        {
          "name": "startTransaction",
          "object": "session0"
        },
        {
          "name": "runCommand",
          "object": "database",
          "command_name": "insert",
          "arguments": {
            "session": "session0",
            "command": {
              "insert": "test",
              "documents": [
                {
                  "_id": 1
                }
              ]
            },
            "readPreference": {
              "mode": "Primary"
            }
          },
          "result": {
            "n": 1
          }
        },
        {
          "name": "commitTransaction",
          "object": "session0"
        }
      ],
      "expectations": [
        {
          "command_started_event": {
            "command": {
              "insert": "test",
              "documents": [
                {
                  "_id": 1
                }
              ],
              "readConcern": null,
              "lsid": "session0",
              "txnNumber": {
                "$numberLong": "1"
              },
              "startTransaction": true,
              "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
            },
            "command_name": "commitTransaction",
            "database_name": "admin"
          }
        }
      ]
    },
    {
      "description": "run command fails with explicit secondary read preference",
      "operations": [
        {
          "name": "startTransaction",
          "object": "session0"
        },
        {
          "name": "runCommand",
          "object": "database",
          "command_name": "find",
          "arguments": {
            "session": "session0",
            "command": {
              "find": "test"
            },
            "readPreference": {
              "mode": "Secondary"
            }
          },
          "result": {
            "errorContains": "read preference in a transaction must be primary"
          }
        }
      ]
    },
    {
      "description": "run command fails with secondary read preference from transaction options",
      "operations": [
        {
          "name": "startTransaction",
          "object": "session0",
          "arguments": {
            "options": {
              "readPreference": {
                "mode": "Secondary"
              }
            }
          }
        },
        {
          "name": "runCommand",
          "object": "database",
          "command_name": "find",
          "arguments": {
            "session": "session0",
            "command": {
              "find": "test"
            }
          },
          "result": {
            "errorContains": "read preference in a transaction must be primary"
          }
        }
      ]
    }
  ]
}
