runOn:
  -
    minServerVersion: "4.3.4"
    topology: ["replicaset", "sharded"]

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

data: []

tests:
  - description: explicitly create collection using create command

    operations:
      - name: dropCollection
        object: database
        arguments:
          collection: *collection_name
      - name: startTransaction
        object: session0
      - name: createCollection
        object: database
        arguments:
          session: session0
          collection: *collection_name
      - name: assertCollectionNotExists
        object: testRunner
        arguments:
          database: *database_name
          collection: *collection_name
      - name: commitTransaction
        object: session0
      - name: assertCollectionExists
        object: testRunner
        arguments:
          database: *database_name
          collection: *collection_name

    expectations:
      - command_started_event:
          command:
            drop: *collection_name
            writeConcern:
          command_name: drop
          database_name: *database_name
      - command_started_event:
          command:
            create: *collection_name
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction: true
            autocommit: false
            writeConcern:
          command_name: create
          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

  - description: implicitly create collection using insert

    operations:
      - name: dropCollection
        object: database
        arguments:
          collection: *collection_name
      - name: startTransaction
        object: session0
      - name: insertOne
        object: collection
        arguments:
          session: session0
          document:
            _id: 1
        result:
          insertedId: 1
      - name: assertCollectionNotExists
        object: testRunner
        arguments:
          database: *database_name
          collection: *collection_name
      - name: commitTransaction
        object: session0
      - name: assertCollectionExists
        object: testRunner
        arguments:
          database: *database_name
          collection: *collection_name

    expectations:
      - command_started_event:
          command:
            drop: *collection_name
            writeConcern:
          command_name: drop
          database_name: *database_name
      - 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
