Skip to content

Commit

Permalink
chore: sync transactions spec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Apr 6, 2020
1 parent 917f2b0 commit e7007d2
Show file tree
Hide file tree
Showing 44 changed files with 2,282 additions and 476 deletions.
118 changes: 108 additions & 10 deletions test/spec/transactions/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ control the fail point's behavior. ``failCommand`` supports the following

- ``failCommands``: Required, the list of command names to fail.
- ``closeConnection``: Boolean option, which defaults to ``false``. If
``true``, the connection on which the command is executed will be closed
and the client will see a network error.
- ``errorCode``: Integer option, which is unset by default. If set, the
specified command error code will be returned as a command error.
``true``, the command will not be executed, the connection will be closed, and
the client will see a network error.
- ``errorCode``: Integer option, which is unset by default. If set, the command
will not be executed and the specified command error code will be returned as
a command error.
- ``writeConcernError``: A document, which is unset by default. If set, the
server will return this document in the "writeConcernError" field. This
failure response only applies to commands that support write concern and
Expand Down Expand Up @@ -121,8 +122,8 @@ Each YAML file has the following keys:
configureFailPoint command to run on the admin database. This option and
``useMultipleMongoses: true`` are mutually exclusive.

- ``sessionOptions``: Optional, parameters to pass to
MongoClient.startSession().
- ``sessionOptions``: Optional, map of session names (e.g. "session0") to
parameters to pass to MongoClient.startSession() when creating that session.

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

- ``databaseOptions``: Optional, parameters to pass to the Database()
used for this operation.

- ``command_name``: Present only when ``name`` is "runCommand". The name
of the command to run. Required for languages that are unable preserve
the order keys in the "command" argument when parsing JSON/YAML.

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

- ``error``: Optional. If true, the test should expect an error or
exception. This could be a server-generated or a driver-generated error.

- ``result``: The return value from the operation, if any. This field may
be a single document or an array of documents in the case of a
multi-document read. If the operation is expected to return an error, the
Expand Down Expand Up @@ -191,7 +198,8 @@ Then for each element in ``tests``:
#. If the ``skipReason`` field is present, skip this test completely.
#. Create a MongoClient and call
``client.admin.runCommand({killAllSessions: []})`` to clean up any open
transactions from previous test failures.
transactions from previous test failures. Ignore a command failure with
error code 11601 ("Interrupted") to work around `SERVER-38335`_.

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

- If the operation ``name`` is a special test operation type, execute it and
Expand All @@ -235,15 +243,18 @@ Then for each element in ``tests``:
field at the top level of the test file.
- Create a Collection object from the Database, using the
``collection_name`` field at the top level of the test file.
If ``collectionOptions`` is present create the Collection object with the
provided options. Otherwise create the object with the default options.
If ``collectionOptions`` or ``databaseOptions`` is present, create the
Collection or Database object with the provided options, respectively.
Otherwise create the object with the default options.
- Execute the named method on the provided ``object``, passing the
arguments listed. Pass ``session0`` or ``session1`` to the method,
depending on which session's name is in the arguments list.
If ``arguments`` contains no "session", pass no explicit session to the
method.
- If the driver throws an exception / returns an error while executing this
series of operations, store the error message and server error code.
- If the operation's ``error`` field is ``true``, verify that the method
threw an exception or returned an error.
- If the result document has an "errorContains" field, verify that the
method threw an exception or returned an error, and that the value of the
"errorContains" field matches the error string. "errorContains" is a
Expand Down Expand Up @@ -289,6 +300,8 @@ Then for each element in ``tests``:
**local read concern** even when the MongoClient is configured with
another read preference or read concern.

.. _SERVER-38335: https://jira.mongodb.org/browse/SERVER-38335

Special Test Operations
```````````````````````

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

Tests that use the "targetedFailPoint" operation do not include
``configureFailPoint`` commands in their command expectations. Drivers MUST
ensure that ``configureFailPoint`` commands do not appear in the list of logged
commands, either by manually filtering it from the list of observed commands or
by using a different MongoClient to execute ``configureFailPoint``.

assertSessionTransactionState
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The "assertSessionTransactionState" operation instructs the test runner to
assert that the transaction state of the given session is equal to the
specified value. The possible values are as follows: ``none``, ``starting``,
``in_progress``, ``committed``, ``aborted``::

- name: assertSessionTransactionState
object: testRunner
arguments:
session: session0
state: in_progress

assertSessionPinned
~~~~~~~~~~~~~~~~~~~

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

assertCollectionExists
~~~~~~~~~~~~~~~~~~~~~~

The "assertCollectionExists" operation instructs the test runner to assert that
the given collection exists in the database::

- name: assertCollectionExists
object: testRunner
arguments:
database: db
collection: test

Use a ``listCollections`` command to check whether the collection exists. Note
that it is currently not possible to run ``listCollections`` from within a
transaction.

assertCollectionNotExists
~~~~~~~~~~~~~~~~~~~~~~~~~

The "assertCollectionNotExists" operation instructs the test runner to assert
that the given collection does not exist in the database::

- name: assertCollectionNotExists
object: testRunner
arguments:
database: db
collection: test

Use a ``listCollections`` command to check whether the collection exists. Note
that it is currently not possible to run ``listCollections`` from within a
transaction.

assertIndexExists
~~~~~~~~~~~~~~~~~

The "assertIndexExists" operation instructs the test runner to assert that the
index with the given name exists on the collection::

- name: assertIndexExists
object: testRunner
arguments:
database: db
collection: test
index: t_1

Use a ``listIndexes`` command to check whether the index exists. Note that it is
currently not possible to run ``listIndexes`` from within a transaction.

assertIndexNotExists
~~~~~~~~~~~~~~~~~~~~

The "assertIndexNotExists" operation instructs the test runner to assert that
the index with the given name does not exist on the collection::

- name: assertIndexNotExists
object: testRunner
arguments:
database: db
collection: test
index: t_1

Use a ``listIndexes`` command to check whether the index exists. Note that it is
currently not possible to run ``listIndexes`` from within a transaction.

Command-Started Events
``````````````````````

Expand Down Expand Up @@ -524,6 +621,7 @@ is the only command allowed in a sharded transaction that uses the
Changelog
=========

:2019-05-15: Add operation level ``error`` field to assert any error.
:2019-03-25: Add workaround for StaleDbVersion on distinct.
:2019-03-01: Add top-level ``runOn`` field to denote server version and/or
topology requirements requirements for the test file. Removes the
Expand Down
3 changes: 2 additions & 1 deletion test/spec/transactions/abort.json
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,8 @@
"errorLabelsOmit": [
"TransientTransactionError",
"UnknownTransactionCommitResult"
]
],
"errorContains": "E11000"
}
},
{
Expand Down
6 changes: 3 additions & 3 deletions test/spec/transactions/abort.yml
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,10 @@ tests:
document:
_id: 1
result:
# Don't assert on errorCodeName because (after SERVER-38583) the
# DuplicateKey is reported in writeErrors, not as a top-level
# command error.
errorLabelsOmit: ["TransientTransactionError", "UnknownTransactionCommitResult"]
# DuplicateKey error code included in the bulk write error message
# returned by the server
errorContains: E11000
# Make sure the server aborted the transaction.
- name: insertOne
object: collection
Expand Down
16 changes: 4 additions & 12 deletions test/spec/transactions/bulk.json
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,7 @@
"$set": {
"x": 1
}
},
"multi": false,
"upsert": false
}
},
{
"q": {
Expand All @@ -317,7 +315,6 @@
"x": 2
}
},
"multi": false,
"upsert": true
}
],
Expand Down Expand Up @@ -379,19 +376,15 @@
},
"u": {
"y": 1
},
"multi": false,
"upsert": false
}
},
{
"q": {
"_id": 2
},
"u": {
"y": 2
},
"multi": false,
"upsert": false
}
}
],
"ordered": true,
Expand Down Expand Up @@ -454,8 +447,7 @@
"z": 1
}
},
"multi": true,
"upsert": false
"multi": true
}
],
"ordered": true,
Expand Down
8 changes: 0 additions & 8 deletions test/spec/transactions/bulk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,8 @@ tests:
updates:
- q: {_id: 1}
u: {$set: {x: 1}}
multi: false
upsert: false
- q: {_id: 2}
u: {$set: {x: 2}}
multi: false
upsert: true
ordered: true
lsid: session0
Expand Down Expand Up @@ -192,12 +189,8 @@ tests:
updates:
- q: {_id: 1}
u: {y: 1}
multi: false
upsert: false
- q: {_id: 2}
u: {y: 2}
multi: false
upsert: false
ordered: true
lsid: session0
txnNumber:
Expand Down Expand Up @@ -231,7 +224,6 @@ tests:
- q: {_id: {$gte: 2}}
u: {$set: {z: 1}}
multi: true
upsert: false
ordered: true
lsid: session0
txnNumber:
Expand Down
21 changes: 6 additions & 15 deletions test/spec/transactions/causal-consistency.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
"$inc": {
"count": 1
}
},
"upsert": false
}
},
"result": {
"matchedCount": 1,
Expand All @@ -65,8 +64,7 @@
"$inc": {
"count": 1
}
},
"upsert": false
}
},
"result": {
"matchedCount": 1,
Expand All @@ -93,9 +91,7 @@
"$inc": {
"count": 1
}
},
"multi": false,
"upsert": false
}
}
],
"ordered": true,
Expand Down Expand Up @@ -123,9 +119,7 @@
"$inc": {
"count": 1
}
},
"multi": false,
"upsert": false
}
}
],
"ordered": true,
Expand Down Expand Up @@ -212,8 +206,7 @@
"$inc": {
"count": 1
}
},
"upsert": false
}
},
"result": {
"matchedCount": 1,
Expand Down Expand Up @@ -260,9 +253,7 @@
"$inc": {
"count": 1
}
},
"multi": false,
"upsert": false
}
}
],
"ordered": true,
Expand Down
Loading

0 comments on commit e7007d2

Please sign in to comment.