{
  "runOn": [
    {
      "minServerVersion": "4.0",
      "topology": [
        "replicaset"
      ]
    },
    {
      "minServerVersion": "4.1.8",
      "topology": [
        "sharded"
      ]
    }
  ],
  "database_name": "session-tests",
  "collection_name": "test",
  "data": [
    {
      "_id": 1
    }
  ],
  "tests": [
    {
      "description": "Dirty explicit session is discarded",
      "clientOptions": {
        "retryWrites": true
      },
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 1
        },
        "data": {
          "failCommands": [
            "insert"
          ],
          "closeConnection": true
        }
      },
      "operations": [
        {
          "name": "assertSessionNotDirty",
          "object": "testRunner",
          "arguments": {
            "session": "session0"
          }
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "session": "session0",
            "document": {
              "_id": 2
            }
          },
          "result": {
            "insertedId": 2
          }
        },
        {
          "name": "assertSessionDirty",
          "object": "testRunner",
          "arguments": {
            "session": "session0"
          }
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "session": "session0",
            "document": {
              "_id": 3
            }
          },
          "result": {
            "insertedId": 3
          }
        },
        {
          "name": "assertSessionDirty",
          "object": "testRunner",
          "arguments": {
            "session": "session0"
          }
        },
        {
          "name": "endSession",
          "object": "session0"
        },
        {
          "name": "find",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": -1
            }
          },
          "result": []
        },
        {
          "name": "assertDifferentLsidOnLastTwoCommands",
          "object": "testRunner"
        }
      ],
      "expectations": [
        {
          "command_started_event": {
            "command": {
              "insert": "test",
              "documents": [
                {
                  "_id": 2
                }
              ],
              "ordered": true,
              "lsid": "session0",
              "txnNumber": {
                "$numberLong": "1"
              }
            },
            "command_name": "insert",
            "database_name": "session-tests"
          }
        },
        {
          "command_started_event": {
            "command": {
              "insert": "test",
              "documents": [
                {
                  "_id": 2
                }
              ],
              "ordered": true,
              "lsid": "session0",
              "txnNumber": {
                "$numberLong": "1"
              }
            },
            "command_name": "insert",
            "database_name": "session-tests"
          }
        },
        {
          "command_started_event": {
            "command": {
              "insert": "test",
              "documents": [
                {
                  "_id": 3
                }
              ],
              "ordered": true,
              "lsid": "session0",
              "txnNumber": {
                "$numberLong": "2"
              }
            },
            "command_name": "insert",
            "database_name": "session-tests"
          }
        },
        {
          "command_started_event": {
            "command": {
              "find": "test",
              "filter": {
                "_id": -1
              }
            },
            "command_name": "find",
            "database_name": "session-tests"
          }
        }
      ],
      "outcome": {
        "collection": {
          "data": [
            {
              "_id": 1
            },
            {
              "_id": 2
            },
            {
              "_id": 3
            }
          ]
        }
      }
    },
    {
      "description": "Dirty explicit session is discarded (non-bulk write)",
      "clientOptions": {
        "retryWrites": true
      },
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 1
        },
        "data": {
          "failCommands": [
            "findAndModify"
          ],
          "closeConnection": true
        }
      },
      "operations": [
        {
          "name": "assertSessionNotDirty",
          "object": "testRunner",
          "arguments": {
            "session": "session0"
          }
        },
        {
          "name": "findOneAndUpdate",
          "object": "collection",
          "arguments": {
            "session": "session0",
            "filter": {
              "_id": 1
            },
            "update": {
              "$inc": {
                "x": 1
              }
            },
            "returnDocument": "Before"
          },
          "result": {
            "_id": 1
          }
        },
        {
          "name": "assertSessionDirty",
          "object": "testRunner",
          "arguments": {
            "session": "session0"
          }
        },
        {
          "name": "endSession",
          "object": "session0"
        },
        {
          "name": "find",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": -1
            }
          },
          "result": []
        },
        {
          "name": "assertDifferentLsidOnLastTwoCommands",
          "object": "testRunner"
        }
      ],
      "expectations": [
        {
          "command_started_event": {
            "command": {
              "findAndModify": "test",
              "query": {
                "_id": 1
              },
              "update": {
                "$inc": {
                  "x": 1
                }
              },
              "new": false,
              "lsid": "session0",
              "txnNumber": {
                "$numberLong": "1"
              },
              "readConcern": null,
              "writeConcern": null
            },
            "command_name": "findAndModify",
            "database_name": "session-tests"
          }
        },
        {
          "command_started_event": {
            "command": {
              "findAndModify": "test",
              "query": {
                "_id": 1
              },
              "update": {
                "$inc": {
                  "x": 1
                }
              },
              "new": false,
              "lsid": "session0",
              "txnNumber": {
                "$numberLong": "1"
              },
              "readConcern": null,
              "writeConcern": null
            },
            "command_name": "findAndModify",
            "database_name": "session-tests"
          }
        },
        {
          "command_started_event": {
            "command": {
              "find": "test",
              "filter": {
                "_id": -1
              }
            },
            "command_name": "find",
            "database_name": "session-tests"
          }
        }
      ],
      "outcome": {
        "collection": {
          "data": [
            {
              "_id": 1,
              "x": 1
            }
          ]
        }
      }
    },
    {
      "description": "Dirty implicit session is discarded (write)",
      "clientOptions": {
        "retryWrites": true
      },
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 1
        },
        "data": {
          "failCommands": [
            "insert"
          ],
          "closeConnection": true
        }
      },
      "operations": [
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "document": {
              "_id": 2
            }
          },
          "result": {
            "insertedId": 2
          }
        },
        {
          "name": "find",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": -1
            }
          },
          "result": []
        },
        {
          "name": "assertDifferentLsidOnLastTwoCommands",
          "object": "testRunner"
        }
      ],
      "expectations": [
        {
          "command_started_event": {
            "command": {
              "insert": "test",
              "documents": [
                {
                  "_id": 2
                }
              ],
              "ordered": true,
              "txnNumber": {
                "$numberLong": "1"
              }
            },
            "command_name": "insert",
            "database_name": "session-tests"
          }
        },
        {
          "command_started_event": {
            "command": {
              "insert": "test",
              "documents": [
                {
                  "_id": 2
                }
              ],
              "ordered": true,
              "txnNumber": {
                "$numberLong": "1"
              }
            },
            "command_name": "insert",
            "database_name": "session-tests"
          }
        },
        {
          "command_started_event": {
            "command": {
              "find": "test",
              "filter": {
                "_id": -1
              }
            },
            "command_name": "find",
            "database_name": "session-tests"
          }
        }
      ],
      "outcome": {
        "collection": {
          "data": [
            {
              "_id": 1
            },
            {
              "_id": 2
            }
          ]
        }
      }
    },
    {
      "description": "Dirty implicit session is discarded (non-bulk write)",
      "clientOptions": {
        "retryWrites": true
      },
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 1
        },
        "data": {
          "failCommands": [
            "findAndModify"
          ],
          "closeConnection": true
        }
      },
      "operations": [
        {
          "name": "findOneAndUpdate",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": 1
            },
            "update": {
              "$inc": {
                "x": 1
              }
            },
            "returnDocument": "Before"
          },
          "result": {
            "_id": 1
          }
        },
        {
          "name": "find",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": -1
            }
          },
          "result": []
        },
        {
          "name": "assertDifferentLsidOnLastTwoCommands",
          "object": "testRunner"
        }
      ],
      "expectations": [
        {
          "command_started_event": {
            "command": {
              "findAndModify": "test",
              "query": {
                "_id": 1
              },
              "update": {
                "$inc": {
                  "x": 1
                }
              },
              "new": false,
              "txnNumber": {
                "$numberLong": "1"
              },
              "readConcern": null,
              "writeConcern": null
            },
            "command_name": "findAndModify",
            "database_name": "session-tests"
          }
        },
        {
          "command_started_event": {
            "command": {
              "findAndModify": "test",
              "query": {
                "_id": 1
              },
              "update": {
                "$inc": {
                  "x": 1
                }
              },
              "new": false,
              "txnNumber": {
                "$numberLong": "1"
              },
              "readConcern": null,
              "writeConcern": null
            },
            "command_name": "findAndModify",
            "database_name": "session-tests"
          }
        },
        {
          "command_started_event": {
            "command": {
              "find": "test",
              "filter": {
                "_id": -1
              }
            },
            "command_name": "find",
            "database_name": "session-tests"
          }
        }
      ],
      "outcome": {
        "collection": {
          "data": [
            {
              "_id": 1,
              "x": 1
            }
          ]
        }
      }
    },
    {
      "description": "Dirty implicit session is discarded (read)",
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 2
        },
        "data": {
          "failCommands": [
            "aggregate"
          ],
          "closeConnection": true
        }
      },
      "operations": [
        {
          "name": "aggregate",
          "object": "collection",
          "arguments": {
            "pipeline": [
              {
                "$project": {
                  "_id": 1
                }
              }
            ]
          },
          "error": true
        },
        {
          "name": "find",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": -1
            }
          },
          "result": []
        },
        {
          "name": "assertDifferentLsidOnLastTwoCommands",
          "object": "testRunner"
        }
      ],
      "outcome": {
        "collection": {
          "data": [
            {
              "_id": 1
            }
          ]
        }
      }
    },
    {
      "description": "Dirty implicit session is discarded (non-cursor returning read)",
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 2
        },
        "data": {
          "failCommands": [
            "aggregate"
          ],
          "closeConnection": true
        }
      },
      "operations": [
        {
          "name": "countDocuments",
          "object": "collection",
          "arguments": {
            "filter": {}
          },
          "error": true
        },
        {
          "name": "find",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": -1
            }
          },
          "result": []
        },
        {
          "name": "assertDifferentLsidOnLastTwoCommands",
          "object": "testRunner"
        }
      ],
      "outcome": {
        "collection": {
          "data": [
            {
              "_id": 1
            }
          ]
        }
      }
    }
  ]
}
