Skip to content

Commit 94d25c3

Browse files
committed
chore: sync transactions spec tests
1 parent 17e4c88 commit 94d25c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2282
-476
lines changed

test/spec/transactions/README.rst

Lines changed: 108 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ control the fail point's behavior. ``failCommand`` supports the following
6161

6262
- ``failCommands``: Required, the list of command names to fail.
6363
- ``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.
6869
- ``writeConcernError``: A document, which is unset by default. If set, the
6970
server will return this document in the "writeConcernError" field. This
7071
failure response only applies to commands that support write concern and
@@ -121,8 +122,8 @@ Each YAML file has the following keys:
121122
configureFailPoint command to run on the admin database. This option and
122123
``useMultipleMongoses: true`` are mutually exclusive.
123124

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.
126127

127128
- ``operations``: Array of documents, each describing an operation to be
128129
executed. Each document has the following fields:
@@ -136,12 +137,18 @@ Each YAML file has the following keys:
136137
- ``collectionOptions``: Optional, parameters to pass to the Collection()
137138
used for this operation.
138139

140+
- ``databaseOptions``: Optional, parameters to pass to the Database()
141+
used for this operation.
142+
139143
- ``command_name``: Present only when ``name`` is "runCommand". The name
140144
of the command to run. Required for languages that are unable preserve
141145
the order keys in the "command" argument when parsing JSON/YAML.
142146

143147
- ``arguments``: Optional, the names and values of arguments.
144148

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+
145152
- ``result``: The return value from the operation, if any. This field may
146153
be a single document or an array of documents in the case of a
147154
multi-document read. If the operation is expected to return an error, the
@@ -191,7 +198,8 @@ Then for each element in ``tests``:
191198
#. If the ``skipReason`` field is present, skip this test completely.
192199
#. Create a MongoClient and call
193200
``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`_.
195203

196204
- Running ``killAllSessions`` cleans up any open transactions from
197205
a previously failed test to prevent the current test from blocking.
@@ -225,7 +233,7 @@ Then for each element in ``tests``:
225233
#. Call ``client.startSession`` twice to create ClientSession objects
226234
``session0`` and ``session1``, using the test's "sessionOptions" if they
227235
are present. Save their lsids so they are available after calling
228-
``endSession``, see `Logical Session Id`.
236+
``endSession``, see `Logical Session Id`_.
229237
#. For each element in ``operations``:
230238

231239
- If the operation ``name`` is a special test operation type, execute it and
@@ -235,15 +243,18 @@ Then for each element in ``tests``:
235243
field at the top level of the test file.
236244
- Create a Collection object from the Database, using the
237245
``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.
240249
- Execute the named method on the provided ``object``, passing the
241250
arguments listed. Pass ``session0`` or ``session1`` to the method,
242251
depending on which session's name is in the arguments list.
243252
If ``arguments`` contains no "session", pass no explicit session to the
244253
method.
245254
- If the driver throws an exception / returns an error while executing this
246255
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.
247258
- If the result document has an "errorContains" field, verify that the
248259
method threw an exception or returned an error, and that the value of the
249260
"errorContains" field matches the error string. "errorContains" is a
@@ -289,6 +300,8 @@ Then for each element in ``tests``:
289300
**local read concern** even when the MongoClient is configured with
290301
another read preference or read concern.
291302

303+
.. _SERVER-38335: https://jira.mongodb.org/browse/SERVER-38335
304+
292305
Special Test Operations
293306
```````````````````````
294307

@@ -329,6 +342,26 @@ fail point on the mongos server which "session0" is pinned to::
329342
failCommands: ["commitTransaction"]
330343
closeConnection: true
331344

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+
332365
assertSessionPinned
333366
~~~~~~~~~~~~~~~~~~~
334367

@@ -351,6 +384,70 @@ the given session is not pinned to a mongos::
351384
arguments:
352385
session: session0
353386

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+
354451
Command-Started Events
355452
``````````````````````
356453

@@ -524,6 +621,7 @@ is the only command allowed in a sharded transaction that uses the
524621
Changelog
525622
=========
526623

624+
:2019-05-15: Add operation level ``error`` field to assert any error.
527625
:2019-03-25: Add workaround for StaleDbVersion on distinct.
528626
:2019-03-01: Add top-level ``runOn`` field to denote server version and/or
529627
topology requirements requirements for the test file. Removes the

test/spec/transactions/abort.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,8 @@
458458
"errorLabelsOmit": [
459459
"TransientTransactionError",
460460
"UnknownTransactionCommitResult"
461-
]
461+
],
462+
"errorContains": "E11000"
462463
}
463464
},
464465
{

test/spec/transactions/abort.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,10 @@ tests:
305305
document:
306306
_id: 1
307307
result:
308-
# Don't assert on errorCodeName because (after SERVER-38583) the
309-
# DuplicateKey is reported in writeErrors, not as a top-level
310-
# command error.
311308
errorLabelsOmit: ["TransientTransactionError", "UnknownTransactionCommitResult"]
309+
# DuplicateKey error code included in the bulk write error message
310+
# returned by the server
311+
errorContains: E11000
312312
# Make sure the server aborted the transaction.
313313
- name: insertOne
314314
object: collection

test/spec/transactions/bulk.json

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,7 @@
304304
"$set": {
305305
"x": 1
306306
}
307-
},
308-
"multi": false,
309-
"upsert": false
307+
}
310308
},
311309
{
312310
"q": {
@@ -317,7 +315,6 @@
317315
"x": 2
318316
}
319317
},
320-
"multi": false,
321318
"upsert": true
322319
}
323320
],
@@ -379,19 +376,15 @@
379376
},
380377
"u": {
381378
"y": 1
382-
},
383-
"multi": false,
384-
"upsert": false
379+
}
385380
},
386381
{
387382
"q": {
388383
"_id": 2
389384
},
390385
"u": {
391386
"y": 2
392-
},
393-
"multi": false,
394-
"upsert": false
387+
}
395388
}
396389
],
397390
"ordered": true,
@@ -454,8 +447,7 @@
454447
"z": 1
455448
}
456449
},
457-
"multi": true,
458-
"upsert": false
450+
"multi": true
459451
}
460452
],
461453
"ordered": true,

test/spec/transactions/bulk.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,8 @@ tests:
153153
updates:
154154
- q: {_id: 1}
155155
u: {$set: {x: 1}}
156-
multi: false
157-
upsert: false
158156
- q: {_id: 2}
159157
u: {$set: {x: 2}}
160-
multi: false
161158
upsert: true
162159
ordered: true
163160
lsid: session0
@@ -192,12 +189,8 @@ tests:
192189
updates:
193190
- q: {_id: 1}
194191
u: {y: 1}
195-
multi: false
196-
upsert: false
197192
- q: {_id: 2}
198193
u: {y: 2}
199-
multi: false
200-
upsert: false
201194
ordered: true
202195
lsid: session0
203196
txnNumber:
@@ -231,7 +224,6 @@ tests:
231224
- q: {_id: {$gte: 2}}
232225
u: {$set: {z: 1}}
233226
multi: true
234-
upsert: false
235227
ordered: true
236228
lsid: session0
237229
txnNumber:

test/spec/transactions/causal-consistency.json

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
"$inc": {
4141
"count": 1
4242
}
43-
},
44-
"upsert": false
43+
}
4544
},
4645
"result": {
4746
"matchedCount": 1,
@@ -65,8 +64,7 @@
6564
"$inc": {
6665
"count": 1
6766
}
68-
},
69-
"upsert": false
67+
}
7068
},
7169
"result": {
7270
"matchedCount": 1,
@@ -93,9 +91,7 @@
9391
"$inc": {
9492
"count": 1
9593
}
96-
},
97-
"multi": false,
98-
"upsert": false
94+
}
9995
}
10096
],
10197
"ordered": true,
@@ -123,9 +119,7 @@
123119
"$inc": {
124120
"count": 1
125121
}
126-
},
127-
"multi": false,
128-
"upsert": false
122+
}
129123
}
130124
],
131125
"ordered": true,
@@ -212,8 +206,7 @@
212206
"$inc": {
213207
"count": 1
214208
}
215-
},
216-
"upsert": false
209+
}
217210
},
218211
"result": {
219212
"matchedCount": 1,
@@ -260,9 +253,7 @@
260253
"$inc": {
261254
"count": 1
262255
}
263-
},
264-
"multi": false,
265-
"upsert": false
256+
}
266257
}
267258
],
268259
"ordered": true,

0 commit comments

Comments
 (0)