...

Text file src/go.mongodb.org/mongo-driver/testdata/versioned-api/transaction-handling.yml

Documentation: go.mongodb.org/mongo-driver/testdata/versioned-api

     1description: "Transaction handling"
     2
     3schemaVersion: "1.1"
     4
     5runOnRequirements:
     6  - minServerVersion: "4.9"
     7    topologies: [ replicaset, sharded-replicaset, load-balanced ]
     8
     9createEntities:
    10  - client:
    11      id: &client client
    12      observeEvents:
    13        - commandStartedEvent
    14      serverApi:
    15        version: "1"
    16  - database:
    17      id: &database database
    18      client: *client
    19      databaseName: &databaseName versioned-api-tests
    20  - collection:
    21      id: &collection collection
    22      database: *database
    23      collectionName: &collectionName test
    24  - session:
    25      id: &session session
    26      client: *client
    27
    28_yamlAnchors:
    29  versions:
    30    - &expectedApiVersion
    31      apiVersion: "1"
    32      apiStrict: { $$unsetOrMatches: false }
    33      apiDeprecationErrors: { $$unsetOrMatches: false }
    34
    35
    36initialData:
    37  - collectionName: *collectionName
    38    databaseName: *databaseName
    39    documents:
    40      - { _id: 1, x: 11 }
    41      - { _id: 2, x: 22 }
    42      - { _id: 3, x: 33 }
    43      - { _id: 4, x: 44 }
    44      - { _id: 5, x: 55 }
    45
    46tests:
    47  - description: "All commands in a transaction declare an API version"
    48    runOnRequirements:
    49      - topologies: [ replicaset, sharded-replicaset, load-balanced ]
    50    operations:
    51      - name: startTransaction
    52        object: *session
    53      - name: insertOne
    54        object: *collection
    55        arguments:
    56          session: *session
    57          document: { _id: 6, x: 66 }
    58        expectResult: { $$unsetOrMatches: { insertedId: { $$unsetOrMatches: 6 } } }
    59      - name: insertOne
    60        object: *collection
    61        arguments:
    62          session: *session
    63          document: { _id: 7, x: 77 }
    64        expectResult: { $$unsetOrMatches: { insertedId: { $$unsetOrMatches: 7 } } }
    65      - name: commitTransaction
    66        object: *session
    67    expectEvents:
    68      - client: *client
    69        events:
    70          - commandStartedEvent:
    71              command:
    72                insert: *collectionName
    73                documents: [ { _id: 6, x: 66 } ]
    74                lsid: { $$sessionLsid: *session }
    75                startTransaction: true
    76                <<: *expectedApiVersion
    77          - commandStartedEvent:
    78              command:
    79                insert: *collectionName
    80                documents: [ { _id: 7, x: 77 } ]
    81                lsid: { $$sessionLsid: *session }
    82                <<: *expectedApiVersion
    83          - commandStartedEvent:
    84              command:
    85                commitTransaction: 1
    86                lsid: { $$sessionLsid: *session }
    87                <<: *expectedApiVersion
    88  - description: "abortTransaction includes an API version"
    89    runOnRequirements:
    90      - topologies: [ replicaset, sharded-replicaset, load-balanced ]
    91    operations:
    92      - name: startTransaction
    93        object: *session
    94      - name: insertOne
    95        object: *collection
    96        arguments:
    97          session: *session
    98          document: { _id: 6, x: 66 }
    99        expectResult: { $$unsetOrMatches: { insertedId: { $$unsetOrMatches: 6 } } }
   100      - name: insertOne
   101        object: *collection
   102        arguments:
   103          session: *session
   104          document: { _id: 7, x: 77 }
   105        expectResult: { $$unsetOrMatches: { insertedId: { $$unsetOrMatches: 7 } } }
   106      - name: abortTransaction
   107        object: *session
   108    expectEvents:
   109      - client: *client
   110        events:
   111          - commandStartedEvent:
   112              command:
   113                insert: *collectionName
   114                documents: [ { _id: 6, x: 66 } ]
   115                lsid: { $$sessionLsid: *session }
   116                startTransaction: true
   117                <<: *expectedApiVersion
   118          - commandStartedEvent:
   119              command:
   120                insert: *collectionName
   121                documents: [ { _id: 7, x: 77 } ]
   122                lsid: { $$sessionLsid: *session }
   123                <<: *expectedApiVersion
   124          - commandStartedEvent:
   125              command:
   126                abortTransaction: 1
   127                lsid: { $$sessionLsid: *session }
   128                <<: *expectedApiVersion

View as plain text