Skip to content

Commit fcff6fe

Browse files
authored
test(NODE-3733): sync remaining unified tests (#3651)
1 parent d7a8079 commit fcff6fe

File tree

4 files changed

+940
-78
lines changed

4 files changed

+940
-78
lines changed

test/spec/retryable-writes/README.rst

+89-20
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,21 @@ Each YAML file has the following keys:
169169
the default is all topologies (i.e. ``["single", "replicaset", "sharded",
170170
"load-balanced"]``).
171171

172-
- ``serverless``: Optional string. Whether or not the test should be run on
173-
serverless instances imitating sharded clusters. Valid values are "require",
174-
"forbid", and "allow". If "require", the test MUST only be run on serverless
175-
instances. If "forbid", the test MUST NOT be run on serverless instances. If
176-
omitted or "allow", this option has no effect.
177-
178-
The test runner MUST be informed whether or not serverless is being used in
179-
order to determine if this requirement is met (e.g. through an environment
180-
variable or configuration option). Since the serverless proxy imitates a
181-
mongos, the runner is not capable of determining this by issuing a server
182-
command such as ``buildInfo`` or ``hello``.
172+
- ``serverless``: (optional): Whether or not the test should be run on Atlas
173+
Serverless instances. Valid values are "require", "forbid", and "allow". If
174+
"require", the test MUST only be run on Atlas Serverless instances. If
175+
"forbid", the test MUST NOT be run on Atlas Serverless instances. If omitted
176+
or "allow", this option has no effect.
177+
178+
The test runner MUST be informed whether or not Atlas Serverless is being
179+
used in order to determine if this requirement is met (e.g. through an
180+
environment variable or configuration option).
181+
182+
Note: the Atlas Serverless proxy imitates mongos, so the test runner is not
183+
capable of determining if Atlas Serverless is in use by issuing commands
184+
such as ``buildInfo`` or ``hello``. Furthermore, connections to Atlas
185+
Serverless use a load balancer, so the topology will appear as
186+
"load-balanced".
183187

184188
- ``data``: The data that should exist in the collection under test before each
185189
test run.
@@ -196,13 +200,14 @@ Each YAML file has the following keys:
196200
mongos seed addresses. If ``false`` or omitted, only a single mongos address
197201
should be specified.
198202

199-
If ``true``, and the topology type is ``LoadBalanced``, the MongoClient for
200-
this test should be initialized with the URI of the load balancer fronting
201-
multiple servers. If ``false`` or omitted, the MongoClient for this test
202-
should be initialized with the URI of the load balancer fronting a single
203-
server.
203+
If ``true``, the topology type is ``LoadBalanced``, and Atlas Serverless is
204+
not being used, the MongoClient for this test should be initialized with the
205+
URI of the load balancer fronting multiple servers. If ``false`` or omitted,
206+
the MongoClient for this test should be initialized with the URI of the load
207+
balancer fronting a single server.
204208

205-
``useMultipleMongoses`` only affects ``Sharded`` and ``LoadBalanced`` topologies.
209+
``useMultipleMongoses`` only affects ``Sharded`` and ``LoadBalanced``
210+
topologies (excluding Atlas Serverless).
206211

207212
- ``failPoint`` (optional): The ``configureFailPoint`` command document to run
208213
to configure a fail point on the primary server. Drivers must ensure that
@@ -286,11 +291,11 @@ Command Construction Tests
286291

287292
Drivers should also assert that command documents are properly constructed with
288293
or without a transaction ID, depending on whether the write operation is
289-
supported. `Command Monitoring`_ may be used to check for the presence of a
294+
supported. `Command Logging and Monitoring`_ may be used to check for the presence of a
290295
``txnNumber`` field in the command document. Note that command documents may
291296
always include an ``lsid`` field per the `Driver Session`_ specification.
292297

293-
.. _Command Monitoring: ../../command-monitoring/command-monitoring.rst
298+
.. _Command Logging and Monitoring: ../../command-logging-and-monitoring/command-logging-and-monitoring.rst
294299
.. _Driver Session: ../../sessions/driver-sessions.rst
295300

296301
These tests may be run against both a replica set and shard cluster.
@@ -348,7 +353,7 @@ and sharded clusters.
348353
retryWrites=false to your connection string.
349354

350355
and the error code is 20.
351-
356+
352357
**Note**: Drivers that rely on ``serverStatus`` to determine the storage engine
353358
in use MAY skip this test for sharded clusters, since ``mongos`` does not report
354359
this information in its ``serverStatus`` response.
@@ -390,11 +395,75 @@ and sharded clusters.
390395

391396
9. Disable the failpoint.
392397

398+
#. Test that drivers return the original error after encountering a
399+
WriteConcernError with a RetryableWriteError label. This test MUST
400+
401+
1. be implemented by any driver that implements the Command Monitoring
402+
specification,
403+
404+
2. only run against replica sets as mongos does not propagate the
405+
NoWritesPerformed label to the drivers.
406+
407+
3. be run against server versions 6.0 and above.
408+
409+
Additionally, this test requires drivers to set a fail point after an
410+
``insertOne`` operation but before the subsequent retry. Drivers that are
411+
unable to set a failCommand after the CommandSucceededEvent SHOULD use
412+
mocking or write a unit test to cover the same sequence of events.
413+
414+
415+
1. Create a client with ``retryWrites=true``.
416+
417+
2. Configure a fail point with error code ``91`` (ShutdownInProgress)::
418+
419+
db.adminCommand({
420+
configureFailPoint: "failCommand",
421+
mode: {times: 1},
422+
data: {
423+
writeConcernError: {
424+
code: 91,
425+
errorLabels: ["RetryableWriteError"],
426+
},
427+
failCommands: ["insert"],
428+
},
429+
});
430+
431+
3. Via the command monitoring CommandSucceededEvent, configure a fail point
432+
with error code ``10107`` (NotWritablePrimary) and a NoWritesPerformed
433+
label::
434+
435+
db.adminCommand({
436+
configureFailPoint: "failCommand",
437+
mode: {times: 1},
438+
data: {
439+
errorCode: 10107,
440+
errorLabels: ["RetryableWriteError", "NoWritesPerformed"],
441+
failCommands: ["insert"],
442+
},
443+
});
444+
445+
Drivers SHOULD only configure the ``10107`` fail point command if the the
446+
succeeded event is for the ``91`` error configured in step 2.
447+
448+
4. Attempt an ``insertOne`` operation on any record for any database and
449+
collection. For the resulting error, assert that the associated error code
450+
is ``91``.
451+
452+
5. Disable the fail point::
453+
454+
db.adminCommand({
455+
configureFailPoint: "failCommand",
456+
mode: "off",
457+
})
393458

394459
Changelog
395460
=========
396461

462+
:2022-08-30: Add prose test verifying correct error handling for errors with
463+
the NoWritesPerformed label, which is to return the original
464+
error.
397465

466+
:2022-04-22: Clarifications to ``serverless`` and ``useMultipleMongoses``.
398467

399468
:2021-08-27: Add ``serverless`` to ``runOn``. Clarify behavior of
400469
``useMultipleMongoses`` for ``LoadBalanced`` topologies.

0 commit comments

Comments
 (0)