@@ -9,192 +9,18 @@ Retryable Reads Tests
9
9
Introduction
10
10
============
11
11
12
- The YAML and JSON files in the ``legacy `` and ``unified `` sub-directories are platform-independent tests
13
- that drivers can use to prove their conformance to the Retryable Reads spec. Tests in the
14
- ``unified `` directory are written using the `Unified Test Format <../../unified-test-format/unified-test-format.rst >`_.
15
- Tests in the ``legacy `` directory are written using the format described below.
12
+ The YAML and JSON files in this directory are platform-independent tests meant
13
+ to exercise a driver's implementation of retryable reads. These tests utilize
14
+ the [Unified Test Format](../../unified-test-format/unified-test-format.md).
16
15
17
- Prose tests, which are not easily expressed in YAML, are also presented
16
+ Several prose tests, which are not easily expressed in YAML, are also presented
18
17
in this file. Those tests will need to be manually implemented by each driver.
19
18
20
- Tests will require a MongoClient created with options defined in the tests.
21
- Integration tests will require a running MongoDB cluster with server versions
22
- 4.0 or later.
19
+ Prose Tests
20
+ ===========
23
21
24
- N.B. The spec specifies 3.6 as the minimum server version: however,
25
- ``failCommand `` is not supported on 3.6, so for now, testing requires MongoDB
26
- 4.0. Once `DRIVERS-560 `_ is resolved, we will attempt to adapt its live failure
27
- integration tests to test Retryable Reads on MongoDB 3.6.
28
-
29
- .. _DRIVERS-560 : https://jira.mongodb.org/browse/DRIVERS-560
30
-
31
- Server Fail Point
32
- =================
33
-
34
- See: `Server Fail Point `_ in the Transactions spec test suite.
35
-
36
- .. _Server Fail Point : ../../transactions/tests#server-fail-point
37
-
38
- Disabling Fail Point after Test Execution
39
- -----------------------------------------
40
-
41
- After each test that configures a fail point, drivers should disable the
42
- ``failCommand `` fail point to avoid spurious failures in
43
- subsequent tests. The fail point may be disabled like so::
44
-
45
- db.runCommand({
46
- configureFailPoint: "failCommand",
47
- mode: "off"
48
- });
49
-
50
- Network Error Tests
51
- ===================
52
-
53
- Network error tests are expressed in YAML and should be run against a standalone,
54
- shard cluster, or single-node replica set.
55
-
56
-
57
- Test Format
58
- -----------
59
-
60
- Each YAML file has the following keys:
61
-
62
- - ``runOn `` (optional): An array of server version and/or topology requirements
63
- for which the tests can be run. If the test environment satisfies one or more
64
- of these requirements, the tests may be executed; otherwise, this file should
65
- be skipped. If this field is omitted, the tests can be assumed to have no
66
- particular requirements and should be executed. Each element will have some or
67
- all of the following fields:
68
-
69
- - ``minServerVersion `` (optional): The minimum server version (inclusive)
70
- required to successfully run the tests. If this field is omitted, it should
71
- be assumed that there is no lower bound on the required server version.
72
-
73
- - ``maxServerVersion `` (optional): The maximum server version (inclusive)
74
- against which the tests can be run successfully. If this field is omitted,
75
- it should be assumed that there is no upper bound on the required server
76
- version.
77
-
78
- - ``topology `` (optional): An array of server topologies against which the
79
- tests can be run successfully. Valid topologies are "single",
80
- "replicaset", "sharded", and "load-balanced". If this field is omitted,
81
- the default is all topologies (i.e. ``["single", "replicaset", "sharded",
82
- "load-balanced"] ``).
83
-
84
- - ``serverless ``: (optional): Whether or not the test should be run on Atlas
85
- Serverless instances. Valid values are "require", "forbid", and "allow". If
86
- "require", the test MUST only be run on Atlas Serverless instances. If
87
- "forbid", the test MUST NOT be run on Atlas Serverless instances. If omitted
88
- or "allow", this option has no effect.
89
-
90
- The test runner MUST be informed whether or not Atlas Serverless is being
91
- used in order to determine if this requirement is met (e.g. through an
92
- environment variable or configuration option).
93
-
94
- Note: the Atlas Serverless proxy imitates mongos, so the test runner is not
95
- capable of determining if Atlas Serverless is in use by issuing commands
96
- such as ``buildInfo `` or ``hello ``. Furthermore, connections to Atlas
97
- Serverless use a load balancer, so the topology will appear as
98
- "load-balanced".
99
-
100
- - ``database_name `` and ``collection_name ``: Optional. The database and
101
- collection to use for testing.
102
-
103
- - ``bucket_name ``: Optional. The GridFS bucket name to use for testing.
104
-
105
- - ``data ``: The data that should exist in the collection(s) under test before
106
- each test run. This will typically be an array of documents to be inserted
107
- into the collection under test (i.e. ``collection_name ``); however, this field
108
- may also be an object mapping collection names to arrays of documents to be
109
- inserted into the specified collection.
110
-
111
- - ``tests ``: An array of tests that are to be run independently of each other.
112
- Each test will have some or all of the following fields:
113
-
114
- - ``description ``: The name of the test.
115
-
116
- - ``clientOptions ``: Optional, parameters to pass to MongoClient().
117
-
118
- - ``useMultipleMongoses `` (optional): If ``true ``, and the topology type is
119
- ``Sharded ``, the MongoClient for this test should be initialized with multiple
120
- mongos seed addresses. If ``false `` or omitted, only a single mongos address
121
- should be specified.
122
-
123
- If ``true ``, the topology type is ``LoadBalanced ``, and Atlas Serverless is
124
- not being used, the MongoClient for this test should be initialized with the
125
- URI of the load balancer fronting multiple servers. If ``false `` or omitted,
126
- the MongoClient for this test should be initialized with the URI of the load
127
- balancer fronting a single server.
128
-
129
- ``useMultipleMongoses `` only affects ``Sharded `` and ``LoadBalanced ``
130
- topologies (excluding Atlas Serverless).
131
-
132
- - ``skipReason ``: Optional, string describing why this test should be skipped.
133
-
134
- - ``failPoint ``: Optional, a server fail point to enable, expressed as the
135
- configureFailPoint command to run on the admin database.
136
-
137
- - ``operations ``: An array of documents describing an operation to be
138
- executed. Each document has the following fields:
139
-
140
- - ``name ``: The name of the operation on ``object ``.
141
-
142
- - ``object ``: The name of the object to perform the operation on. Can be
143
- "database", "collection", "client", or "gridfsbucket."
144
-
145
- - ``arguments ``: Optional, the names and values of arguments.
146
-
147
- - ``result ``: Optional. The return value from the operation, if any. This
148
- field may be a scalar (e.g. in the case of a count), a single document, or
149
- an array of documents in the case of a multi-document read.
150
-
151
- - ``error ``: Optional. If ``true ``, the test should expect an error or
152
- exception.
153
-
154
- - ``expectations ``: Optional list of command-started events.
155
-
156
- GridFS Tests
157
- ------------
158
-
159
- GridFS tests are denoted by when the YAML file contains ``bucket_name ``.
160
- The ``data `` field will also be an object, which maps collection names
161
- (e.g. ``fs.files ``) to an array of documents that should be inserted into
162
- the specified collection.
163
-
164
- ``fs.files `` and ``fs.chunks `` should be created in the database
165
- specified by ``database_name ``. This could be done via inserts or by
166
- creating GridFSBuckets—using the GridFS ``bucketName `` (see
167
- `GridFSBucket spec `_) specified by ``bucket_name `` field in the YAML
168
- file—and calling ``upload_from_stream_with_id `` with the appropriate
169
- data.
170
-
171
- ``Download `` tests should be tested against ``GridFS.download_to_stream ``.
172
- ``DownloadByName `` tests should be tested against
173
- ``GridFS.download_to_stream_by_name ``.
174
-
175
-
176
- .. _GridFSBucket spec : https://github.com/mongodb/specifications/blob/master/source/gridfs/gridfs-spec.rst#configurable-gridfsbucket-class
177
-
178
-
179
- Speeding Up Tests
180
- -----------------
181
-
182
- Drivers can greatly reduce the execution time of tests by setting `heartbeatFrequencyMS `_
183
- and `minHeartbeatFrequencyMS `_ (internally) to a small value (e.g. 5ms), below what
184
- is normally permitted in the SDAM spec. If a test specifies an explicit value for
185
- heartbeatFrequencyMS (e.g. client or URI options), drivers MUST use that value.
186
-
187
- .. _minHeartbeatFrequencyMS : ../../server-discovery-and-monitoring/server-discovery-and-monitoring.rst#minheartbeatfrequencyms
188
- .. _heartbeatFrequencyMS : ../../server-discovery-and-monitoring/server-discovery-and-monitoring.rst#heartbeatfrequencyms
189
-
190
- Optional Enumeration Commands
191
- =============================
192
-
193
- A driver only needs to test the optional enumeration commands it has chosen to
194
- implement (e.g. ``Database.listCollectionNames() ``).
195
-
196
- PoolClearedError Retryability Test
197
- ==================================
22
+ 1. PoolClearedError Retryability Test
23
+ -------------------------------------
198
24
199
25
This test will be used to ensure drivers properly retry after encountering PoolClearedErrors.
200
26
It MUST be implemented by any driver that implements the CMAP specification.
@@ -232,79 +58,96 @@ This test requires MongoDB 4.2.9+ for ``blockConnection`` support in the failpoi
232
58
233
59
9. Disable the failpoint.
234
60
235
- Retrying Reads in a Sharded Cluster
236
- ===================================
61
+ 2. Retrying Reads in a Sharded Cluster
62
+ --------------------------------------
237
63
238
64
These tests will be used to ensure drivers properly retry reads on a different
239
65
mongos.
240
66
241
- Retryable Reads Are Retried on a Different mongos if One is Available
242
- ---------------------------------------------------------------------
67
+ Note: this test cannot reliably distinguish "retry on a different mongos due to
68
+ server deprioritization" (the behavior intended to be tested) from "retry on a
69
+ different mongos due to normal SDAM behavior of randomized suitable server
70
+ selection". Verify relevant code paths are correctly executed by the tests using
71
+ external means such as a logging, debugger, code coverage tool, etc.
72
+
73
+ 2.1 Retryable Reads Are Retried on a Different mongos When One is Available
74
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
243
75
244
76
This test MUST be executed against a sharded cluster that has at least two
245
- mongos instances.
77
+ mongos instances, supports ``retryReads=true ``, and has enabled the
78
+ ``configureFailPoint `` command (MongoDB 4.2+).
246
79
247
- 1. Ensure that a test is run against a sharded cluster that has at least two
248
- mongoses. If there are more than two mongoses in the cluster, pick two to
249
- test against.
80
+ 1. Create two clients ``s0 `` and ``s1 `` that each connect to a single mongos
81
+ from the sharded cluster. They must not connect to the same mongos.
250
82
251
- 2. Create a client per mongos using the direct connection, and configure the
252
- following fail points on each mongos::
83
+ 2. Configure the following fail point for both ``s0 `` and ``s1 ``::
253
84
254
85
{
255
86
configureFailPoint: "failCommand",
256
87
mode: { times: 1 },
257
88
data: {
258
89
failCommands: ["find"],
259
- errorCode: 6,
260
- closeConnection: true
90
+ errorCode: 6
261
91
}
262
92
}
263
93
264
- 3. Create a client with ``retryReads=true `` that connects to the cluster,
265
- providing the two selected mongoses as seeds.
94
+ 3. Create a client ``client `` with ``retryReads=true `` that connects to the
95
+ cluster using the same two mongoses as ``s0 `` and ``s1 ``.
96
+
97
+ 4. Enable failed command event monitoring for ``client ``.
98
+
99
+ 5. Execute a ``find `` command with ``client ``. Assert that the command failed.
266
100
267
- 4. Enable command monitoring, and execute a `` find `` command that is
268
- supposed to fail on both mongoses.
101
+ 6. Assert that two failed command events occurred. Assert that both events
102
+ occurred on different mongoses.
269
103
270
- 5. Asserts that there were failed command events from each mongos .
104
+ 7. Disable the fail point on both `` s0 `` and `` s1 `` .
271
105
272
- 6. Disable the fail points.
273
106
107
+ 2.2 Retryable Reads Are Retried on the Same mongos When No Others are Available
108
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
274
109
275
- Retryable Reads Are Retried on the Same mongos if No Others are Available
276
- -------------------------------------------------------------------------
110
+ This test MUST be executed against a sharded cluster that supports
111
+ ``retryReads=true `` and has enabled the ``configureFailPoint `` command
112
+ (MongoDB 4.2+).
277
113
278
- 1. Ensure that a test is run against a sharded cluster. If there are multiple
279
- mongoses in the cluster, pick one to test against.
114
+ 1. Create a client ``s0 `` that connects to a single mongos from the cluster.
280
115
281
- 2. Create a client that connects to the mongos using the direct connection,
282
- and configure the following fail point on the mongos::
116
+ 2. Configure the following fail point for ``s0 ``::
283
117
284
118
{
285
119
configureFailPoint: "failCommand",
286
120
mode: { times: 1 },
287
121
data: {
288
122
failCommands: ["find"],
289
- errorCode: 6,
290
- closeConnection: true
123
+ errorCode: 6
291
124
}
292
125
}
293
126
294
- 3. Create a client with ``retryReads=true `` that connects to the cluster,
295
- providing the selected mongos as the seed.
127
+ 3. Create a client ``client `` with ``directConnection=false `` (when not set by
128
+ default) and ``retryReads=true `` that connects to the cluster using the same
129
+ single mongos as ``s0 ``.
296
130
297
- 4. Enable command monitoring, and execute a `` find `` command .
131
+ 4. Enable succeeded and failed command event monitoring for `` client `` .
298
132
299
- 5. Asserts that there was a failed command and a successful command event.
133
+ 5. Execute a ``find `` command with ``client ``. Assert that the command
134
+ succeeded.
300
135
301
- 6. Disable the fail point.
136
+ 6. Assert that exactly one failed command event and one succeeded command event
137
+ occurred. Assert that both events occurred on the same mongos.
138
+
139
+ 7. Disable the fail point on ``s0 ``.
302
140
303
141
304
142
Changelog
305
143
=========
306
144
307
- :2023-08-26 Add prose tests for retrying in a sharded cluster.
145
+ :2024-03-06: Convert legacy retryable reads tests to unified format.
146
+
147
+ :2024-02-21: Update mongos redirection prose tests to workaround SDAM behavior
148
+ preventing execution of deprioritization code paths.
149
+
150
+ :2023-08-26: Add prose tests for retrying in a sharded cluster.
308
151
309
152
:2022-04-22: Clarifications to ``serverless `` and ``useMultipleMongoses ``.
310
153
0 commit comments