@@ -17,6 +17,56 @@ tests and the Command Monitoring Spec tests.
17
17
Several prose tests, which are not easily expressed in YAML, are also presented
18
18
in this file. Those tests will need to be manually implemented by each driver.
19
19
20
+ Server Fail Point
21
+ =================
22
+
23
+ Some tests depend on a server fail point, expressed in the ``failPoint `` field.
24
+ For example the ``failCommand `` fail point allows the client to force the
25
+ server to return an error. Keep in mind that the fail point only triggers for
26
+ commands listed in the "failCommands" field. See `SERVER-35004 `_ and
27
+ `SERVER-35083 `_ for more information.
28
+
29
+ .. _SERVER-35004 : https://jira.mongodb.org/browse/SERVER-35004
30
+ .. _SERVER-35083 : https://jira.mongodb.org/browse/SERVER-35083
31
+
32
+ The ``failCommand `` fail point may be configured like so::
33
+
34
+ db.adminCommand({
35
+ configureFailPoint: "failCommand",
36
+ mode: <string|document>,
37
+ data: {
38
+ failCommands: ["commandName", "commandName2"],
39
+ closeConnection: <true|false>,
40
+ errorCode: <Number>,
41
+ writeConcernError: <document>
42
+ }
43
+ });
44
+
45
+ ``mode `` is a generic fail point option and may be assigned a string or document
46
+ value. The string values ``"alwaysOn" `` and ``"off" `` may be used to enable or
47
+ disable the fail point, respectively. A document may be used to specify either
48
+ ``times `` or ``skip ``, which are mutually exclusive:
49
+
50
+ - ``{ times: <integer> } `` may be used to limit the number of times the fail
51
+ point may trigger before transitioning to ``"off" ``.
52
+ - ``{ skip: <integer> } `` may be used to defer the first trigger of a fail
53
+ point, after which it will transition to ``"alwaysOn" ``.
54
+
55
+ The ``data `` option is a document that may be used to specify options that
56
+ control the fail point's behavior. ``failCommand `` supports the following
57
+ ``data `` options, which may be combined if desired:
58
+
59
+ - ``failCommands ``: Required, the list of command names to fail.
60
+ - ``closeConnection ``: Boolean option, which defaults to ``false ``. If
61
+ ``true ``, the connection on which the command is executed will be closed
62
+ and the client will see a network error.
63
+ - ``errorCode ``: Integer option, which is unset by default. If set, the
64
+ specified command error code will be returned as a command error.
65
+ - ``writeConcernError ``: A document, which is unset by default. If set, the
66
+ server will return this document in the "writeConcernError" field. This
67
+ failure response only applies to commands that support write concern and
68
+ happens *after * the command finishes (regardless of success or failure).
69
+
20
70
Test Format
21
71
===========
22
72
@@ -35,41 +85,54 @@ Each YAML file has the following keys:
35
85
36
86
- ``clientOptions ``: Optional, parameters to pass to MongoClient().
37
87
88
+ - ``failPoint ``: Optional, a server failpoint to enable expressed as the
89
+ configureFailPoint command to run on the admin database.
90
+
38
91
- ``sessionOptions ``: Optional, parameters to pass to
39
92
MongoClient.startSession().
40
93
41
94
- ``operations ``: Array of documents, each describing an operation to be
42
95
executed. Each document has the following fields:
43
96
44
- - ``name ``: The name of the operation on ``object ``.
97
+ - ``name ``: The name of the operation on ``object ``.
98
+
99
+ - ``object ``: The name of the object to perform the operation on. Can be
100
+ "database", "collection", "session0", or "session1".
101
+
102
+ - ``collectionOptions ``: Optional, parameters to pass to the Collection()
103
+ used for this operation.
104
+
105
+ - ``command_name ``: Present only when ``name `` is "runCommand". The name
106
+ of the command to run. Required for languages that are unable preserve
107
+ the order keys in the "command" argument when parsing JSON/YAML.
108
+
109
+ - ``arguments ``: Optional, the names and values of arguments.
45
110
46
- - ``object ``: The name of the object to perform the operation on. Can be
47
- "database", collection", "session0", or "session1".
111
+ - ``result ``: The return value from the operation, if any. If the
112
+ operation is expected to return an error, the ``result `` has one of
113
+ the following fields:
48
114
49
- - ``collectionOptions ``: Optional, parameters to pass to the Collection()
50
- used for this operation.
115
+ - ``errorContains ``: A substring of the expected error message.
51
116
52
- - ``command_name ``: Present only when ``name `` is "runCommand". The name
53
- of the command to run. Required for languages that are unable preserve
54
- the order keys in the "command" argument when parsing JSON/YAML.
117
+ - ``errorCodeName ``: The expected "codeName" field in the server
118
+ error response.
55
119
56
- - ``arguments ``: Optional, the names and values of arguments.
120
+ - ``errorLabelsContain ``: A list of error label strings that the
121
+ error is expected to have.
57
122
58
- - ``result ``: The return value from the operation, if any. If the
59
- operation is expected to return an error, the ``result `` has one field,
60
- ``errorContains ``, which is a substring of the expected error message
61
- or ``errorCodeName ``, which is the expected server error "codeName".
123
+ - ``errorLabelsOmit ``: A list of error label strings that the
124
+ error is expected not to have.
62
125
63
126
- ``expectations ``: Optional list of command-started events.
64
127
65
128
- ``outcome ``: Document describing the return value and/or expected state of
66
129
the collection after the operation is executed. Contains the following
67
130
fields:
68
131
69
- - ``collection ``:
132
+ - ``collection ``:
70
133
71
- - ``data ``: The data that should exist in the collection after the
72
- operations have run.
134
+ - ``data ``: The data that should exist in the collection after the
135
+ operations have run.
73
136
74
137
Use as integration tests
75
138
========================
@@ -96,6 +159,8 @@ Then for each element in ``tests``:
96
159
create it explicitly.)
97
160
#. If the YAML file contains a ``data `` array, insert the documents in ``data ``
98
161
into the test collection, using writeConcern "majority".
162
+ #. If ``failPoint `` is specified, its value is a configureFailPoint command.
163
+ Run the command on the admin database to enable the fail point.
99
164
#. Create a **new ** MongoClient ``client ``, with Command Monitoring listeners
100
165
enabled. (Using a new MongoClient for each test ensures a fresh session pool
101
166
that hasn't executed any transactions previously, so the tests can assert
@@ -125,11 +190,22 @@ Then for each element in ``tests``:
125
190
method threw an exception or returned an error, and that the value of the
126
191
"errorContains" field matches the error string. "errorContains" is a
127
192
substring (case-insensitive) of the actual error message.
193
+
128
194
If the result document has an "errorCodeName" field, verify that the
129
195
method threw a command failed exception or returned an error, and that
130
196
the value of the "errorCodeName" field matches the "codeName" in the
131
197
server error response.
132
- If the operation returns a raw command response, eg from ``runCommand ``,
198
+
199
+ If the result document has an "errorLabelsContain" field, verify that the
200
+ method threw an exception or returned an error. Verify that all of the
201
+ error labels in "errorLabelsContain" are present in the error or exception
202
+ using the ``hasErrorLabel `` method.
203
+
204
+ If the result document has an "errorLabelsOmit" field, verify that the
205
+ method threw an exception or returned an error. Verify that none of the
206
+ error labels in "errorLabelsOmit" are present in the error or exception
207
+ using the ``hasErrorLabel `` method.
208
+ - If the operation returns a raw command response, eg from ``runCommand ``,
133
209
then compare only the fields present in the expected result document.
134
210
Otherwise, compare the method's return value to ``result `` using the same
135
211
logic as the CRUD Spec Tests runner.
@@ -139,6 +215,14 @@ Then for each element in ``tests``:
139
215
compare them to the actual command-started events using the
140
216
same logic as the Command Monitoring Spec Tests runner, plus the rules in
141
217
the Command-Started Events instructions below.
218
+ #. If ``failPoint `` is specified, disable the fail point to avoid spurious
219
+ failures in subsequent tests. The fail point may be disabled like so::
220
+
221
+ db.adminCommand({
222
+ configureFailPoint: <fail point name>,
223
+ mode: "off"
224
+ });
225
+
142
226
#. For each element in ``outcome ``:
143
227
144
228
- If ``name `` is "collection", verify that the test collection contains
@@ -148,7 +232,6 @@ Then for each element in ``tests``:
148
232
149
233
TODO:
150
234
151
- - drivers MUST NOT retry writes in a transaction even when retryWrites=true, needs to use failpoint.
152
235
- drivers MUST retry commit/abort, needs to use failpoint.
153
236
- test writeConcernErrors
154
237
0 commit comments