{
  "description": "poc-transactions-mongos-pin-auto",
  "schemaVersion": "1.0",
  "runOnRequirements": [
    {
      "minServerVersion": "4.1.8",
      "topologies": [
        "sharded-replicaset"
      ]
    }
  ],
  "createEntities": [
    {
      "client": {
        "id": "client0",
        "useMultipleMongoses": true,
        "observeEvents": [
          "commandStartedEvent"
        ]
      }
    },
    {
      "database": {
        "id": "database0",
        "client": "client0",
        "databaseName": "transaction-tests"
      }
    },
    {
      "collection": {
        "id": "collection0",
        "database": "database0",
        "collectionName": "test"
      }
    },
    {
      "session": {
        "id": "session0",
        "client": "client0"
      }
    }
  ],
  "initialData": [
    {
      "collectionName": "test",
      "databaseName": "transaction-tests",
      "documents": [
        {
          "_id": 1
        },
        {
          "_id": 2
        }
      ]
    }
  ],
  "tests": [
    {
      "description": "remain pinned after non-transient Interrupted error on insertOne",
      "operations": [
        {
          "name": "startTransaction",
          "object": "session0"
        },
        {
          "name": "insertOne",
          "object": "collection0",
          "arguments": {
            "session": "session0",
            "document": {
              "_id": 3
            }
          },
          "expectResult": {
            "$$unsetOrMatches": {
              "insertedId": {
                "$$unsetOrMatches": 3
              }
            }
          }
        },
        {
          "name": "targetedFailPoint",
          "object": "testRunner",
          "arguments": {
            "session": "session0",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 1
              },
              "data": {
                "failCommands": [
                  "insert"
                ],
                "errorCode": 11601
              }
            }
          }
        },
        {
          "name": "insertOne",
          "object": "collection0",
          "arguments": {
            "session": "session0",
            "document": {
              "_id": 4
            }
          },
          "expectError": {
            "errorLabelsOmit": [
              "TransientTransactionError",
              "UnknownTransactionCommitResult"
            ],
            "errorCodeName": "Interrupted"
          }
        },
        {
          "name": "assertSessionPinned",
          "object": "testRunner",
          "arguments": {
            "session": "session0"
          }
        },
        {
          "name": "commitTransaction",
          "object": "session0"
        }
      ],
      "expectEvents": [
        {
          "client": "client0",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "insert": "test",
                  "documents": [
                    {
                      "_id": 3
                    }
                  ],
                  "ordered": true,
                  "readConcern": {
                    "$$exists": false
                  },
                  "lsid": {
                    "$$sessionLsid": "session0"
                  },
                  "txnNumber": 1,
                  "startTransaction": true,
                  "autocommit": false,
                  "writeConcern": {
                    "$$exists": false
                  }
                },
                "commandName": "insert",
                "databaseName": "transaction-tests"
              }
            },
            {
              "commandStartedEvent": {
                "command": {
                  "insert": "test",
                  "documents": [
                    {
                      "_id": 4
                    }
                  ],
                  "ordered": true,
                  "readConcern": {
                    "$$exists": false
                  },
                  "lsid": {
                    "$$sessionLsid": "session0"
                  },
                  "txnNumber": 1,
                  "startTransaction": {
                    "$$exists": false
                  },
                  "autocommit": false,
                  "writeConcern": {
                    "$$exists": false
                  }
                },
                "commandName": "insert",
                "databaseName": "transaction-tests"
              }
            },
            {
              "commandStartedEvent": {
                "command": {
                  "commitTransaction": 1,
                  "lsid": {
                    "$$sessionLsid": "session0"
                  },
                  "txnNumber": 1,
                  "startTransaction": {
                    "$$exists": false
                  },
                  "autocommit": false,
                  "writeConcern": {
                    "$$exists": false
                  },
                  "recoveryToken": {
                    "$$type": "object"
                  }
                },
                "commandName": "commitTransaction",
                "databaseName": "admin"
              }
            }
          ]
        }
      ],
      "outcome": [
        {
          "collectionName": "test",
          "databaseName": "transaction-tests",
          "documents": [
            {
              "_id": 1
            },
            {
              "_id": 2
            },
            {
              "_id": 3
            }
          ]
        }
      ]
    },
    {
      "description": "unpin after transient error within a transaction",
      "operations": [
        {
          "name": "startTransaction",
          "object": "session0"
        },
        {
          "name": "insertOne",
          "object": "collection0",
          "arguments": {
            "session": "session0",
            "document": {
              "_id": 3
            }
          },
          "expectResult": {
            "$$unsetOrMatches": {
              "insertedId": {
                "$$unsetOrMatches": 3
              }
            }
          }
        },
        {
          "name": "targetedFailPoint",
          "object": "testRunner",
          "arguments": {
            "session": "session0",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 1
              },
              "data": {
                "failCommands": [
                  "insert"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "name": "insertOne",
          "object": "collection0",
          "arguments": {
            "session": "session0",
            "document": {
              "_id": 4
            }
          },
          "expectError": {
            "errorLabelsContain": [
              "TransientTransactionError"
            ],
            "errorLabelsOmit": [
              "UnknownTransactionCommitResult"
            ]
          }
        },
        {
          "name": "assertSessionUnpinned",
          "object": "testRunner",
          "arguments": {
            "session": "session0"
          }
        },
        {
          "name": "abortTransaction",
          "object": "session0"
        }
      ],
      "expectEvents": [
        {
          "client": "client0",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "insert": "test",
                  "documents": [
                    {
                      "_id": 3
                    }
                  ],
                  "ordered": true,
                  "readConcern": {
                    "$$exists": false
                  },
                  "lsid": {
                    "$$sessionLsid": "session0"
                  },
                  "txnNumber": 1,
                  "startTransaction": true,
                  "autocommit": false,
                  "writeConcern": {
                    "$$exists": false
                  }
                },
                "commandName": "insert",
                "databaseName": "transaction-tests"
              }
            },
            {
              "commandStartedEvent": {
                "command": {
                  "insert": "test",
                  "documents": [
                    {
                      "_id": 4
                    }
                  ],
                  "ordered": true,
                  "readConcern": {
                    "$$exists": false
                  },
                  "lsid": {
                    "$$sessionLsid": "session0"
                  },
                  "txnNumber": 1,
                  "startTransaction": {
                    "$$exists": false
                  },
                  "autocommit": false,
                  "writeConcern": {
                    "$$exists": false
                  }
                },
                "commandName": "insert",
                "databaseName": "transaction-tests"
              }
            },
            {
              "commandStartedEvent": {
                "command": {
                  "abortTransaction": 1,
                  "lsid": {
                    "$$sessionLsid": "session0"
                  },
                  "txnNumber": 1,
                  "startTransaction": {
                    "$$exists": false
                  },
                  "autocommit": false,
                  "writeConcern": {
                    "$$exists": false
                  },
                  "recoveryToken": {
                    "$$type": "object"
                  }
                },
                "commandName": "abortTransaction",
                "databaseName": "admin"
              }
            }
          ]
        }
      ],
      "outcome": [
        {
          "collectionName": "test",
          "databaseName": "transaction-tests",
          "documents": [
            {
              "_id": 1
            },
            {
              "_id": 2
            }
          ]
        }
      ]
    }
  ]
}
