...

Text file src/go.mongodb.org/mongo-driver/testdata/unified-test-format/valid-pass/poc-retryable-writes.yml

Documentation: go.mongodb.org/mongo-driver/testdata/unified-test-format/valid-pass

     1description: "poc-retryable-writes"
     2
     3schemaVersion: "1.0"
     4
     5runOnRequirements:
     6  - minServerVersion: "3.6"
     7    topologies: [ replicaset ]
     8
     9createEntities:
    10  - client:
    11      id: &client0 client0
    12      useMultipleMongoses: false
    13      observeEvents: [ commandStartedEvent ]
    14  - client:
    15      id: &client1 client1
    16      uriOptions: { retryWrites: false }
    17      useMultipleMongoses: false
    18      observeEvents: [ commandStartedEvent ]
    19  - database:
    20      id: &database0 database0
    21      client: *client0
    22      databaseName: &databaseName retryable-writes-tests
    23  - database:
    24      id: &database1 database1
    25      client: *client1
    26      databaseName: *databaseName
    27  - collection:
    28      id: &collection0 collection0
    29      database: *database0
    30      collectionName: &collectionName coll
    31  - collection:
    32      id: &collection1 collection1
    33      database: *database1
    34      collectionName: *collectionName
    35
    36initialData:
    37  - collectionName: *collectionName
    38    databaseName: *databaseName
    39    documents:
    40      - { _id: 1, x: 11 }
    41      - { _id: 2, x: 22 }
    42
    43tests:
    44  - description: "FindOneAndUpdate is committed on first attempt"
    45    operations:
    46      - name: failPoint
    47        object: testRunner
    48        arguments:
    49          client: *client0
    50          failPoint:
    51            configureFailPoint: onPrimaryTransactionalWrite
    52            mode: { times: 1 }
    53      - name: findOneAndUpdate
    54        object: *collection0
    55        arguments:
    56          filter: { _id: 1 }
    57          update: { $inc: { x : 1 } }
    58          returnDocument: Before
    59        expectResult: { _id: 1, x: 11 }
    60    outcome:
    61      - collectionName: *collectionName
    62        databaseName: *databaseName
    63        documents:
    64          - { _id: 1, x: 12 }
    65          - { _id: 2, x: 22 }
    66
    67  - description: "FindOneAndUpdate is not committed on first attempt"
    68    operations:
    69      - name: failPoint
    70        object: testRunner
    71        arguments:
    72          client: *client0
    73          failPoint:
    74            configureFailPoint: onPrimaryTransactionalWrite
    75            mode: { times: 1 }
    76            data: { failBeforeCommitExceptionCode: 1 }
    77      - name: findOneAndUpdate
    78        object: *collection0
    79        arguments:
    80          filter: { _id: 1 }
    81          update: { $inc: { x : 1 } }
    82          returnDocument: Before
    83        expectResult: { _id: 1, x: 11 }
    84    outcome:
    85      - collectionName: *collectionName
    86        databaseName: *databaseName
    87        documents:
    88          - { _id: 1, x: 12 }
    89          - { _id: 2, x: 22 }
    90
    91  - description: "FindOneAndUpdate is never committed"
    92    operations:
    93      - name: failPoint
    94        object: testRunner
    95        arguments:
    96          client: *client0
    97          failPoint:
    98            configureFailPoint: onPrimaryTransactionalWrite
    99            mode: { times: 2 }
   100            data: { failBeforeCommitExceptionCode: 1 }
   101      - name: findOneAndUpdate
   102        object: *collection0
   103        arguments:
   104          filter: { _id: 1 }
   105          update: { $inc: { x : 1 } }
   106          returnDocument: Before
   107        expectError: { isError: true }
   108    outcome:
   109      - collectionName: *collectionName
   110        databaseName: *databaseName
   111        documents:
   112          - { _id: 1, x: 11 }
   113          - { _id: 2, x: 22 }
   114
   115  - description: "InsertMany succeeds after PrimarySteppedDown"
   116    runOnRequirements: &failCommand_requirements
   117      - minServerVersion: "4.0"
   118        topologies: [ replicaset ]
   119      - minServerVersion: "4.1.7"
   120        # Original test uses "sharded", but retryable writes requires a sharded
   121        # cluster backed by replica sets
   122        topologies: [ sharded-replicaset ]
   123    operations:
   124      - name: failPoint
   125        object: testRunner
   126        arguments:
   127          client: *client0
   128          failPoint:
   129            configureFailPoint: failCommand
   130            mode: { times: 1 }
   131            data:
   132              failCommands: [ insert ]
   133              errorCode: 189 # PrimarySteppedDown
   134              errorLabels: [  RetryableWriteError ]
   135      - name: insertMany
   136        object: *collection0
   137        arguments:
   138          documents:
   139            # Documents are modified from original test for "initialData"
   140            - { _id: 3, x: 33 }
   141            - { _id: 4, x: 44 }
   142          ordered: true
   143        expectResult:
   144          # InsertManyResult is optional because all of its fields are optional
   145          $$unsetOrMatches: { insertedIds: { $$unsetOrMatches: { 0: 3, 1: 4 } } }
   146    outcome:
   147      - collectionName: *collectionName
   148        databaseName: *databaseName
   149        documents:
   150          - { _id: 1, x: 11 }
   151          - { _id: 2, x: 22 }
   152          - { _id: 3, x: 33 }
   153          - { _id: 4, x: 44 }
   154
   155  - description: "InsertOne fails after connection failure when retryWrites option is false"
   156    runOnRequirements: *failCommand_requirements
   157    operations:
   158      - name: failPoint
   159        object: testRunner
   160        arguments:
   161          client: *client1
   162          failPoint:
   163            configureFailPoint: failCommand
   164            mode: { times: 1 }
   165            data:
   166                failCommands: [ insert ]
   167                closeConnection: true
   168      - name: insertOne
   169        object: *collection1
   170        arguments:
   171          document: { _id: 3, x: 33 }
   172        expectError:
   173          # If retryWrites is false, the driver should not add the
   174          # RetryableWriteError label to the error.
   175          errorLabelsOmit: [ RetryableWriteError ]
   176    outcome:
   177      - collectionName: *collectionName
   178        databaseName: *databaseName
   179        documents:
   180          - { _id: 1, x: 11 }
   181          - { _id: 2, x: 22 }
   182
   183  - description: "InsertOne fails after multiple retryable writeConcernErrors"
   184    runOnRequirements: *failCommand_requirements
   185    operations:
   186      - name: failPoint
   187        object: testRunner
   188        arguments:
   189          client: *client0
   190          failPoint:
   191            configureFailPoint: failCommand
   192            mode: { times: 2 }
   193            data:
   194              failCommands: [ insert ]
   195              writeConcernError:
   196                code: 91 # ShutdownInProgress
   197                errmsg: "Replication is being shut down"
   198      - name: insertOne
   199        object: *collection0
   200        arguments:
   201          document: { _id: 3, x: 33 }
   202        expectError:
   203          errorLabelsContain: [ RetryableWriteError ]
   204    outcome:
   205      - collectionName: *collectionName
   206        databaseName: *databaseName
   207        documents:
   208          - { _id: 1, x: 11 }
   209          - { _id: 2, x: 22 }
   210          - { _id: 3, x: 33 }  # The write was still applied

View as plain text