@@ -61,10 +61,11 @@ control the fail point's behavior. ``failCommand`` supports the following
61
61
62
62
- ``failCommands ``: Required, the list of command names to fail.
63
63
- ``closeConnection ``: Boolean option, which defaults to ``false ``. If
64
- ``true ``, the connection on which the command is executed will be closed
65
- and the client will see a network error.
66
- - ``errorCode ``: Integer option, which is unset by default. If set, the
67
- specified command error code will be returned as a command error.
64
+ ``true ``, the command will not be executed, the connection will be closed, and
65
+ the client will see a network error.
66
+ - ``errorCode ``: Integer option, which is unset by default. If set, the command
67
+ will not be executed and the specified command error code will be returned as
68
+ a command error.
68
69
- ``writeConcernError ``: A document, which is unset by default. If set, the
69
70
server will return this document in the "writeConcernError" field. This
70
71
failure response only applies to commands that support write concern and
@@ -121,8 +122,8 @@ Each YAML file has the following keys:
121
122
configureFailPoint command to run on the admin database. This option and
122
123
``useMultipleMongoses: true `` are mutually exclusive.
123
124
124
- - ``sessionOptions ``: Optional, parameters to pass to
125
- MongoClient.startSession().
125
+ - ``sessionOptions ``: Optional, map of session names (e.g. "session0") to
126
+ parameters to pass to MongoClient.startSession() when creating that session .
126
127
127
128
- ``operations ``: Array of documents, each describing an operation to be
128
129
executed. Each document has the following fields:
@@ -136,12 +137,18 @@ Each YAML file has the following keys:
136
137
- ``collectionOptions ``: Optional, parameters to pass to the Collection()
137
138
used for this operation.
138
139
140
+ - ``databaseOptions ``: Optional, parameters to pass to the Database()
141
+ used for this operation.
142
+
139
143
- ``command_name ``: Present only when ``name `` is "runCommand". The name
140
144
of the command to run. Required for languages that are unable preserve
141
145
the order keys in the "command" argument when parsing JSON/YAML.
142
146
143
147
- ``arguments ``: Optional, the names and values of arguments.
144
148
149
+ - ``error ``: Optional. If true, the test should expect an error or
150
+ exception. This could be a server-generated or a driver-generated error.
151
+
145
152
- ``result ``: The return value from the operation, if any. This field may
146
153
be a single document or an array of documents in the case of a
147
154
multi-document read. If the operation is expected to return an error, the
@@ -191,7 +198,8 @@ Then for each element in ``tests``:
191
198
#. If the ``skipReason `` field is present, skip this test completely.
192
199
#. Create a MongoClient and call
193
200
``client.admin.runCommand({killAllSessions: []}) `` to clean up any open
194
- transactions from previous test failures.
201
+ transactions from previous test failures. Ignore a command failure with
202
+ error code 11601 ("Interrupted") to work around `SERVER-38335 `_.
195
203
196
204
- Running ``killAllSessions `` cleans up any open transactions from
197
205
a previously failed test to prevent the current test from blocking.
@@ -225,7 +233,7 @@ Then for each element in ``tests``:
225
233
#. Call ``client.startSession `` twice to create ClientSession objects
226
234
``session0 `` and ``session1 ``, using the test's "sessionOptions" if they
227
235
are present. Save their lsids so they are available after calling
228
- ``endSession ``, see `Logical Session Id `.
236
+ ``endSession ``, see `Logical Session Id `_ .
229
237
#. For each element in ``operations ``:
230
238
231
239
- If the operation ``name `` is a special test operation type, execute it and
@@ -235,15 +243,18 @@ Then for each element in ``tests``:
235
243
field at the top level of the test file.
236
244
- Create a Collection object from the Database, using the
237
245
``collection_name `` field at the top level of the test file.
238
- If ``collectionOptions `` is present create the Collection object with the
239
- provided options. Otherwise create the object with the default options.
246
+ If ``collectionOptions `` or ``databaseOptions `` is present, create the
247
+ Collection or Database object with the provided options, respectively.
248
+ Otherwise create the object with the default options.
240
249
- Execute the named method on the provided ``object ``, passing the
241
250
arguments listed. Pass ``session0 `` or ``session1 `` to the method,
242
251
depending on which session's name is in the arguments list.
243
252
If ``arguments `` contains no "session", pass no explicit session to the
244
253
method.
245
254
- If the driver throws an exception / returns an error while executing this
246
255
series of operations, store the error message and server error code.
256
+ - If the operation's ``error `` field is ``true ``, verify that the method
257
+ threw an exception or returned an error.
247
258
- If the result document has an "errorContains" field, verify that the
248
259
method threw an exception or returned an error, and that the value of the
249
260
"errorContains" field matches the error string. "errorContains" is a
@@ -289,6 +300,8 @@ Then for each element in ``tests``:
289
300
**local read concern ** even when the MongoClient is configured with
290
301
another read preference or read concern.
291
302
303
+ .. _SERVER-38335 : https://jira.mongodb.org/browse/SERVER-38335
304
+
292
305
Special Test Operations
293
306
```````````````````````
294
307
@@ -329,6 +342,26 @@ fail point on the mongos server which "session0" is pinned to::
329
342
failCommands: ["commitTransaction"]
330
343
closeConnection: true
331
344
345
+ Tests that use the "targetedFailPoint" operation do not include
346
+ ``configureFailPoint `` commands in their command expectations. Drivers MUST
347
+ ensure that ``configureFailPoint `` commands do not appear in the list of logged
348
+ commands, either by manually filtering it from the list of observed commands or
349
+ by using a different MongoClient to execute ``configureFailPoint ``.
350
+
351
+ assertSessionTransactionState
352
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
353
+
354
+ The "assertSessionTransactionState" operation instructs the test runner to
355
+ assert that the transaction state of the given session is equal to the
356
+ specified value. The possible values are as follows: ``none ``, ``starting ``,
357
+ ``in_progress ``, ``committed ``, ``aborted ``::
358
+
359
+ - name: assertSessionTransactionState
360
+ object: testRunner
361
+ arguments:
362
+ session: session0
363
+ state: in_progress
364
+
332
365
assertSessionPinned
333
366
~~~~~~~~~~~~~~~~~~~
334
367
@@ -351,6 +384,70 @@ the given session is not pinned to a mongos::
351
384
arguments:
352
385
session: session0
353
386
387
+ assertCollectionExists
388
+ ~~~~~~~~~~~~~~~~~~~~~~
389
+
390
+ The "assertCollectionExists" operation instructs the test runner to assert that
391
+ the given collection exists in the database::
392
+
393
+ - name: assertCollectionExists
394
+ object: testRunner
395
+ arguments:
396
+ database: db
397
+ collection: test
398
+
399
+ Use a ``listCollections `` command to check whether the collection exists. Note
400
+ that it is currently not possible to run ``listCollections `` from within a
401
+ transaction.
402
+
403
+ assertCollectionNotExists
404
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
405
+
406
+ The "assertCollectionNotExists" operation instructs the test runner to assert
407
+ that the given collection does not exist in the database::
408
+
409
+ - name: assertCollectionNotExists
410
+ object: testRunner
411
+ arguments:
412
+ database: db
413
+ collection: test
414
+
415
+ Use a ``listCollections `` command to check whether the collection exists. Note
416
+ that it is currently not possible to run ``listCollections `` from within a
417
+ transaction.
418
+
419
+ assertIndexExists
420
+ ~~~~~~~~~~~~~~~~~
421
+
422
+ The "assertIndexExists" operation instructs the test runner to assert that the
423
+ index with the given name exists on the collection::
424
+
425
+ - name: assertIndexExists
426
+ object: testRunner
427
+ arguments:
428
+ database: db
429
+ collection: test
430
+ index: t_1
431
+
432
+ Use a ``listIndexes `` command to check whether the index exists. Note that it is
433
+ currently not possible to run ``listIndexes `` from within a transaction.
434
+
435
+ assertIndexNotExists
436
+ ~~~~~~~~~~~~~~~~~~~~
437
+
438
+ The "assertIndexNotExists" operation instructs the test runner to assert that
439
+ the index with the given name does not exist on the collection::
440
+
441
+ - name: assertIndexNotExists
442
+ object: testRunner
443
+ arguments:
444
+ database: db
445
+ collection: test
446
+ index: t_1
447
+
448
+ Use a ``listIndexes `` command to check whether the index exists. Note that it is
449
+ currently not possible to run ``listIndexes `` from within a transaction.
450
+
354
451
Command-Started Events
355
452
``````````````````````
356
453
@@ -524,6 +621,7 @@ is the only command allowed in a sharded transaction that uses the
524
621
Changelog
525
622
=========
526
623
624
+ :2019-05-15: Add operation level ``error `` field to assert any error.
527
625
:2019-03-25: Add workaround for StaleDbVersion on distinct.
528
626
:2019-03-01: Add top-level ``runOn `` field to denote server version and/or
529
627
topology requirements requirements for the test file. Removes the
0 commit comments