...

Text file src/go.mongodb.org/mongo-driver/testdata/convenient-transactions/callback-commits.yml

Documentation: go.mongodb.org/mongo-driver/testdata/convenient-transactions

     1runOn:
     2    -
     3        minServerVersion: "4.0"
     4        topology: ["replicaset"]
     5    -
     6        minServerVersion: "4.1.8"
     7        topology: ["sharded"]
     8
     9database_name: &database_name "withTransaction-tests"
    10collection_name: &collection_name "test"
    11
    12data: []
    13
    14tests:
    15  -
    16    # Session state will be COMMITTED when callback returns to withTransaction
    17    description: withTransaction succeeds if callback commits
    18    useMultipleMongoses: true
    19    operations:
    20      -
    21        name: withTransaction
    22        object: session0
    23        arguments:
    24          callback:
    25            operations:
    26              -
    27                name: insertOne
    28                object: collection
    29                arguments:
    30                  session: session0
    31                  document: { _id: 1 }
    32                result:
    33                  insertedId: 1
    34              -
    35                name: insertOne
    36                object: collection
    37                arguments:
    38                  session: session0
    39                  document: { _id: 2 }
    40                result:
    41                  insertedId: 2
    42              -
    43                name: commitTransaction
    44                object: session0
    45    expectations:
    46      -
    47        command_started_event:
    48          command:
    49            insert: *collection_name
    50            documents:
    51              - { _id: 1 }
    52            ordered: true
    53            lsid: session0
    54            txnNumber: { $numberLong: "1" }
    55            startTransaction: true
    56            autocommit: false
    57            # omitted fields
    58            readConcern: ~
    59            writeConcern: ~
    60          command_name: insert
    61          database_name: *database_name
    62      -
    63        command_started_event:
    64          command:
    65            insert: *collection_name
    66            documents:
    67              - { _id: 2 }
    68            ordered: true
    69            lsid: session0
    70            txnNumber: { $numberLong: "1" }
    71            autocommit: false
    72            # omitted fields
    73            readConcern: ~
    74            startTransaction: ~
    75            writeConcern: ~
    76          command_name: insert
    77          database_name: *database_name
    78      -
    79        command_started_event:
    80          command:
    81            commitTransaction: 1
    82            lsid: session0
    83            txnNumber: { $numberLong: "1" }
    84            autocommit: false
    85            # omitted fields
    86            readConcern: ~
    87            startTransaction: ~
    88            writeConcern: ~
    89          command_name: commitTransaction
    90          database_name: admin
    91    outcome:
    92      collection:
    93        data:
    94          - { _id: 1 }
    95          - { _id: 2 }
    96  -
    97    # Session state will be NO_TXN when callback returns to withTransaction
    98    description: withTransaction still succeeds if callback commits and runs extra op
    99    useMultipleMongoses: true
   100    operations:
   101      -
   102        name: withTransaction
   103        object: session0
   104        arguments:
   105          callback:
   106            operations:
   107              -
   108                name: insertOne
   109                object: collection
   110                arguments:
   111                  session: session0
   112                  document: { _id: 1 }
   113                result:
   114                  insertedId: 1
   115              -
   116                name: insertOne
   117                object: collection
   118                arguments:
   119                  session: session0
   120                  document: { _id: 2 }
   121                result:
   122                  insertedId: 2
   123              -
   124                name: commitTransaction
   125                object: session0
   126              -
   127                name: insertOne
   128                object: collection
   129                arguments:
   130                  session: session0
   131                  document: { _id: 3 }
   132                result:
   133                  insertedId: 3
   134    expectations:
   135      -
   136        command_started_event:
   137          command:
   138            insert: *collection_name
   139            documents:
   140              - { _id: 1 }
   141            ordered: true
   142            lsid: session0
   143            txnNumber: { $numberLong: "1" }
   144            startTransaction: true
   145            autocommit: false
   146            # omitted fields
   147            readConcern: ~
   148            writeConcern: ~
   149          command_name: insert
   150          database_name: *database_name
   151      -
   152        command_started_event:
   153          command:
   154            insert: *collection_name
   155            documents:
   156              - { _id: 2 }
   157            ordered: true
   158            lsid: session0
   159            txnNumber: { $numberLong: "1" }
   160            autocommit: false
   161            # omitted fields
   162            readConcern: ~
   163            startTransaction: ~
   164            writeConcern: ~
   165          command_name: insert
   166          database_name: *database_name
   167      -
   168        command_started_event:
   169          command:
   170            commitTransaction: 1
   171            lsid: session0
   172            txnNumber: { $numberLong: "1" }
   173            autocommit: false
   174            # omitted fields
   175            readConcern: ~
   176            startTransaction: ~
   177            writeConcern: ~
   178          command_name: commitTransaction
   179          database_name: admin
   180      -
   181        command_started_event:
   182          command:
   183            # This test is agnostic about retryWrites, so we do not assert the
   184            # txnNumber. If retryWrites=true, the txnNumber will be incremented
   185            # from the value used in the previous transaction; otherwise, the
   186            # field will not be present at all.
   187            insert: *collection_name
   188            documents:
   189              - { _id: 3 }
   190            ordered: true
   191            lsid: session0
   192            # omitted fields
   193            autocommit: ~
   194            readConcern: ~
   195            startTransaction: ~
   196            writeConcern: ~
   197          command_name: insert
   198          database_name: *database_name
   199    outcome:
   200      collection:
   201        data:
   202          - { _id: 1 }
   203          - { _id: 2 }
   204          - { _id: 3 }

View as plain text