...

Text file src/go.mongodb.org/mongo-driver/testdata/load-balancers/sdam-error-handling.yml

Documentation: go.mongodb.org/mongo-driver/testdata/load-balancers

     1description: state change errors are correctly handled
     2
     3schemaVersion: '1.3'
     4
     5runOnRequirements:
     6  - topologies: [ load-balanced ]
     7
     8_yamlAnchors:
     9  observedEvents: &observedEvents
    10    - connectionCreatedEvent
    11    - connectionReadyEvent
    12    - connectionCheckedOutEvent
    13    - connectionCheckOutFailedEvent
    14    - connectionCheckedInEvent
    15    - connectionClosedEvent
    16    - poolClearedEvent
    17
    18createEntities:
    19  - client:
    20      id: &failPointClient failPointClient
    21      useMultipleMongoses: false
    22  - client:
    23      id: &singleClient singleClient
    24      useMultipleMongoses: false
    25      uriOptions:
    26        appname: &singleClientAppName lbSDAMErrorTestClient
    27        retryWrites: false
    28      observeEvents: *observedEvents
    29  - database:
    30      id: &singleDB singleDB
    31      client: *singleClient
    32      databaseName: &singleDBName singleDB
    33  - collection:
    34      id: &singleColl singleColl
    35      database: *singleDB
    36      collectionName: &singleCollName singleColl
    37  - client:
    38      id: &multiClient multiClient
    39      useMultipleMongoses: true
    40      uriOptions:
    41        retryWrites: false
    42      observeEvents: *observedEvents
    43  - database:
    44      id: &multiDB multiDB
    45      client: *multiClient
    46      databaseName: &multiDBName multiDB
    47  - collection:
    48      id: &multiColl multiColl
    49      database: *multiDB
    50      collectionName: &multiCollName multiColl
    51
    52initialData:
    53  - collectionName: *singleCollName
    54    databaseName: *singleDBName
    55    documents:
    56      - _id: 1
    57      - _id: 2
    58      - _id: 3
    59  - collectionName: *multiCollName
    60    databaseName: *multiDBName
    61    documents:
    62      - _id: 1
    63      - _id: 2
    64      - _id: 3
    65
    66tests:
    67  - description: only connections for a specific serviceId are closed when pools are cleared
    68    runOnRequirements:
    69    # This test assumes that two sequential connections receive different serviceIDs.
    70    # Sequential connections to a serverless instance may receive the same serviceID.
    71    - serverless: forbid
    72    operations:
    73      # Create two cursors to force two connections.
    74      - name: createFindCursor
    75        object: *multiColl
    76        arguments:
    77          filter: {}
    78          batchSize: 2
    79        saveResultAsEntity: &cursor0 cursor0
    80      - name: createFindCursor
    81        object: *multiColl
    82        arguments:
    83          filter: {}
    84          batchSize: 2
    85        saveResultAsEntity: &cursor1 cursor1
    86      # Close both cursors to return the connections to the pool.
    87      - name: close
    88        object: *cursor0
    89      - name: close
    90        object: *cursor1
    91      # Fail an operation with a state change error.
    92      - name: failPoint
    93        object: testRunner
    94        arguments:
    95          client: *multiClient
    96          failPoint:
    97            configureFailPoint: failCommand
    98            mode: { times: 1 }
    99            data:
   100              failCommands: [insert]
   101              errorCode: &errorCode 11600 # InterruptedAtShutdown
   102      - name: insertOne
   103        object: *multiColl
   104        arguments:
   105          document: { x: 1 }
   106        expectError:
   107          errorCode: *errorCode
   108      # Do another operation to ensure the relevant connection has been closed.
   109      - name: insertOne
   110        object: *multiColl
   111        arguments:
   112          document: { x: 1 }
   113    expectEvents:
   114      - client: *multiClient
   115        eventType: cmap
   116        events:
   117          # Create cursors.
   118          - connectionCreatedEvent: {}
   119          - connectionReadyEvent: {}
   120          - connectionCheckedOutEvent: {}
   121          - connectionCreatedEvent: {}
   122          - connectionReadyEvent: {}
   123          - connectionCheckedOutEvent: {}
   124          # Close cursors.
   125          - connectionCheckedInEvent: {}
   126          - connectionCheckedInEvent: {}
   127          # Set failpoint.
   128          - connectionCheckedOutEvent: {}
   129          - connectionCheckedInEvent: {}
   130          # First insertOne.
   131          - connectionCheckedOutEvent: {}
   132          - poolClearedEvent: {}
   133          - connectionCheckedInEvent: {}
   134          - connectionClosedEvent:
   135              reason: stale
   136          # Second insertOne.
   137          - connectionCheckedOutEvent: {}
   138          - connectionCheckedInEvent: {}
   139
   140  # This test uses singleClient to ensure that connection attempts are routed
   141  # to the same mongos on which the failpoint is set.
   142  - description: errors during the initial connection hello are ignore 
   143    runOnRequirements:
   144      # Server version 4.9+ is needed to set a fail point on the initial
   145      # connection handshake with the appName filter due to SERVER-49336.
   146      - minServerVersion: '4.9'
   147    operations:
   148      - name: failPoint
   149        object: testRunner
   150        arguments:
   151          client: *failPointClient
   152          failPoint:
   153            configureFailPoint: failCommand
   154            mode: { times: 1 }
   155            data:
   156              failCommands: [isMaster, hello]
   157              closeConnection: true
   158              appName: *singleClientAppName
   159      - name: insertOne
   160        object: *singleColl
   161        arguments:
   162          document: { x: 1 }
   163        expectError:
   164          isClientError: true
   165    expectEvents:
   166      - client: *singleClient
   167        eventType: cmap
   168        events:
   169          - connectionCreatedEvent: {}
   170          - connectionClosedEvent:
   171              reason: error
   172          - connectionCheckOutFailedEvent:
   173              reason: connectionError
   174
   175  - description: errors during authentication are processed
   176    runOnRequirements:
   177      - auth: true
   178    operations:
   179      - name: failPoint
   180        object: testRunner
   181        arguments:
   182          client: *failPointClient
   183          failPoint:
   184            configureFailPoint: failCommand
   185            mode: { times: 1 }
   186            data:
   187              failCommands: [saslContinue]
   188              closeConnection: true
   189              appName: *singleClientAppName
   190      - name: insertOne
   191        object: *singleColl
   192        arguments:
   193          document: { x: 1 }
   194        expectError:
   195          isClientError: true
   196    expectEvents:
   197      - client: *singleClient
   198        eventType: cmap
   199        events:
   200          - connectionCreatedEvent: {}
   201          - poolClearedEvent: {}
   202          - connectionClosedEvent:
   203              reason: error
   204          - connectionCheckOutFailedEvent:
   205              reason: connectionError
   206
   207  - description: stale errors are ignored
   208    operations:
   209      - name: failPoint
   210        object: testRunner
   211        arguments:
   212          client: *failPointClient
   213          failPoint:
   214            configureFailPoint: failCommand
   215            mode: { times: 2 }
   216            data:
   217              failCommands: [getMore]
   218              closeConnection: true
   219      # Force two connections to be checked out from the pool.
   220      - name: createFindCursor
   221        object: *singleColl
   222        arguments:
   223          filter: {}
   224          batchSize: 2
   225        saveResultAsEntity: &cursor0 cursor0
   226      - name: createFindCursor
   227        object: *singleColl
   228        arguments:
   229          filter: {}
   230          batchSize: 2
   231        saveResultAsEntity: &cursor1 cursor1
   232      # Iterate cursor0 three times to force a network error.
   233      - name: iterateUntilDocumentOrError
   234        object: *cursor0
   235      - name: iterateUntilDocumentOrError
   236        object: *cursor0
   237      - name: iterateUntilDocumentOrError
   238        object: *cursor0
   239        expectError:
   240          isClientError: true
   241      - name: close
   242        object: *cursor0
   243      # Iterate cursor1 three times to force a network error.
   244      - name: iterateUntilDocumentOrError
   245        object: *cursor1
   246      - name: iterateUntilDocumentOrError
   247        object: *cursor1
   248      - name: iterateUntilDocumentOrError
   249        object: *cursor1
   250        expectError:
   251          isClientError: true
   252      - name: close
   253        object: *cursor1
   254    expectEvents:
   255      - client: *singleClient
   256        eventType: cmap
   257        events:
   258          # Events for creating both cursors.
   259          - connectionCreatedEvent: {}
   260          - connectionReadyEvent: {}
   261          - connectionCheckedOutEvent: {}
   262          - connectionCreatedEvent: {}
   263          - connectionReadyEvent: {}
   264          - connectionCheckedOutEvent: {}
   265          # Events for iterating and closing the first cursor.  The failed
   266          # getMore should cause a poolClearedEvent to be published.
   267          - poolClearedEvent: {}
   268          - connectionCheckedInEvent: {}
   269          - connectionClosedEvent: {}
   270          # Events for iterating and closing the second cursor. The failed
   271          # getMore should not clear the pool because the connection's
   272          # generation number is stale.
   273          - connectionCheckedInEvent: {}
   274          - connectionClosedEvent: {}

View as plain text