Skip to content

Commit 54183ff

Browse files
durranljhaywar
authored andcommitted
test(NODE-3709): sync / crud spec tests (#3013)
1 parent 12318d0 commit 54183ff

6 files changed

+1274
-125
lines changed

test/functional/crud_spec.test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,15 @@ describe('CRUD spec v1', function () {
424424
}
425425
});
426426

427+
// TODO: Unskip when implementing NODE-3083.
428+
const SKIP = ['aggregate-write-readPreference', 'db-aggregate-write-readPreference'];
429+
427430
describe('CRUD unified', function () {
428431
for (const crudSpecTest of loadSpecTests('crud/unified')) {
429432
expect(crudSpecTest).to.exist;
430-
context(String(crudSpecTest.description), function () {
433+
const testDescription = String(crudSpecTest.description);
434+
const spec = SKIP.includes(testDescription) ? context.skip : context;
435+
spec(testDescription, function () {
431436
for (const test of crudSpecTest.tests) {
432437
it(String(test.description), {
433438
metadata: { sessions: { skipLeakTests: true } },

test/spec/crud/README.rst

Lines changed: 64 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -19,126 +19,28 @@ version requirements as noted by the ``runOn`` section, if provided.
1919
Subdirectories for Test Formats
2020
-------------------------------
2121

22-
This document describes a current test format, which should be used for any new
23-
CRUD tests. Additionally, it refers to a "legacy" format, which dates back to
24-
the initial version of the CRUD specification. Until such time that all original
25-
tests have been ported to the current format, tests in each format will be
26-
grouped in their own subdirectory:
22+
This document describes a legacy format for CRUD tests: legacy-v1, which dates back
23+
to the first version of the CRUD specification. New CRUD tests should be written
24+
in the `unified test format <../../unified-test-format/unified-test-format.rst>`_
25+
and placed under ``unified/``. Until such time that all original tests have been ported
26+
to the unified test format, tests in each format will be grouped in their own subdirectory:
2727

28-
- ``v1/``: Legacy format tests
29-
- ``v2/``: Current format tests
28+
- ``v1/``: Legacy-v1 format tests
29+
- ``unified/``: Tests using the `unified test format <../../unified-test-format/unified-test-format.rst>`_
3030

3131
Since some drivers may not have a unified test runner capable of executing tests
32-
in both formats, segregating tests in this manner will make it easier for
32+
in all two formats, segregating tests in this manner will make it easier for
3333
drivers to sync and feed test files to different test runners.
3434

35-
Test Format
36-
===========
37-
38-
*Note: this section pertains to test files in the "v2" directory.*
39-
40-
Each YAML file has the following keys:
41-
42-
- ``runOn`` (optional): An array of server version and/or topology requirements
43-
for which the tests can be run. If the test environment satisfies one or more
44-
of these requirements, the tests may be executed; otherwise, this file should
45-
be skipped. If this field is omitted, the tests can be assumed to have no
46-
particular requirements and should be executed. Each element will have some or
47-
all of the following fields:
48-
49-
- ``minServerVersion`` (optional): The minimum server version (inclusive)
50-
required to successfully run the tests. If this field is omitted, it should
51-
be assumed that there is no lower bound on the required server version.
52-
53-
- ``maxServerVersion`` (optional): The maximum server version (inclusive)
54-
against which the tests can be run successfully. If this field is omitted,
55-
it should be assumed that there is no upper bound on the required server
56-
version.
57-
58-
- ``topology`` (optional): An array of server topologies against which the
59-
tests can be run successfully. Valid topologies are "single", "replicaset",
60-
and "sharded". If this field is omitted, the default is all topologies (i.e.
61-
``["single", "replicaset", "sharded"]``).
62-
63-
- ``collection_name`` (optional): The collection to use for testing.
64-
65-
- ``database_name`` (optional): The database to use for testing.
66-
67-
- ``data`` (optional): The data that should exist in the collection under test before each
68-
test run.
69-
70-
- ``tests``: An array of tests that are to be run independently of each other.
71-
Each test will have some or all of the following fields:
72-
73-
- ``description``: The name of the test.
74-
75-
- ``skipReason`` (optional): If present, the test should be skipped and the
76-
string value will specify a reason.
77-
78-
- ``failPoint`` (optional): The ``configureFailPoint`` command document to run
79-
to configure a fail point on the primary server.
80-
81-
- ``clientOptions`` (optional): Names and values of options used to construct
82-
the MongoClient for this test.
83-
84-
- ``operations``: Array of documents, each describing an operation to be
85-
executed. Each document has the following fields:
86-
87-
- ``object`` (optional): The name of the object to perform the operation on. Can be
88-
"database" or "collection". Defaults to "collection" if undefined.
89-
90-
- ``collectionOptions`` (optional): Names and values of options used to
91-
construct the collection object for this test.
92-
93-
- ``name``: The name of the operation as defined in the specification.
94-
95-
- ``arguments``: The names and values of arguments from the specification.
96-
97-
- ``error`` (optional): If ``true``, the test should expect the operation
98-
to emit an error or exception. If ``false`` or omitted, drivers MUST
99-
assert that no error occurred.
100-
101-
- ``result`` (optional): The result of executing the operation. This will
102-
correspond to operation's return value as defined in the specification.
103-
This field may be omitted if ``error`` is ``true``. If this field is
104-
present and ``error`` is ``true`` (generally for multi-statement tests),
105-
the result reports information about statements that succeeded before an
106-
unrecoverable failure. In that case, drivers may choose to check the
107-
result object if their BulkWriteException (or equivalent) provides access
108-
to a write result object.
109-
110-
- ``expectations`` (optional): Array of documents, each describing a
111-
`CommandStartedEvent <../../command-monitoring/command-monitoring.rst#api>`_
112-
from the
113-
`Command Monitoring <../../command-monitoring/command-monitoring.rst>`_
114-
specification. If present, drivers should use command monitoring to observe
115-
events emitted during execution of the test operation(s) and assert that
116-
they match the expected CommandStartedEvent(s). Each document will have the
117-
following field:
118-
119-
- ``command_started_event``: Document corresponding to an expected
120-
`CommandStartedEvent <../../command-monitoring/command-monitoring.rst#api>`_.
121-
122-
- ``outcome`` (optional): Document describing the expected state of the
123-
collection after the operation is executed. Contains the following fields:
124-
125-
- ``collection``:
126-
127-
- ``name`` (optional): The name of the collection to verify. If this isn't
128-
present then use the collection under test.
129-
130-
- ``data``: The data that should exist in the collection after the
131-
operation has been run, sorted by "_id".
132-
133-
Legacy Test Format for Single Operations
134-
----------------------------------------
35+
Legacy-v1 Test Format for Single Operations
36+
-------------------------------------------
13537

13638
*Note: this section pertains to test files in the "v1" directory.*
13739

13840
The test format above supports both multiple operations and APM expectations,
13941
and is consistent with the formats used by other specifications. Previously, the
14042
CRUD spec tests used a simplified format that only allowed for executing a
141-
single operation. Notable differences from the current format are as follows:
43+
single operation. Notable differences from the legacy-v2 format are as follows:
14244

14345
- Instead of a ``tests[i].operations`` array, a single operation was defined as
14446
a document in ``tests[i].operation``. That document consisted of only the
@@ -150,15 +52,17 @@ single operation. Notable differences from the current format are as follows:
15052
fields.
15153

15254
- Instead of a top-level ``runOn`` field, server requirements are denoted by
153-
separate top-level ``minServerVersion`` and ``maxServerVersion`` fields. The
154-
minimum server version is an inclusive lower bound for running the test. The
155-
maximum server version is an exclusive upper bound for running the test. If a
156-
field is not present, it should be assumed that there is no corresponding bound
157-
on the required server version.
158-
159-
The legacy format should not conflict with the newer, multi-operation format
55+
separate top-level ``minServerVersion``, ``maxServerVersion``, and
56+
``serverless`` fields. The minimum server version is an inclusive lower bound
57+
for running the test. The maximum server version is an exclusive upper bound
58+
for running the test. If a field is not present, it should be assumed that
59+
there is no corresponding bound on the required server version. The
60+
``serverless`` requirement behaves the same as the ``serverless`` field of the
61+
`unified test format's runOnRequirement <../../unified-test-format/unified-test-format.rst#runonrequirement>`_.
62+
63+
The legacy-v1 format should not conflict with the newer, multi-operation format
16064
used by other specs (e.g. Transactions). It is possible to create a unified test
161-
runner capable of executing both formats (as some drivers do).
65+
runner capable of executing both legacy formats (as some drivers do).
16266

16367
Error Assertions for Bulk Write Operations
16468
==========================================
@@ -172,7 +76,9 @@ messages into the bulk write exception's top-level message.
17276
Test Runner Implementation
17377
==========================
17478

175-
This section provides guidance for implementing a test runner.
79+
This section provides guidance for implementing a test runner for legacy-v1
80+
tests. See the `unified test format spec <../../../../unified-test-format/unified-test-format.rst>`_ for how to run tests under
81+
``unified/``.
17682

17783
Before running the tests:
17884

@@ -216,8 +122,8 @@ For each test file:
216122

217123
- Activate command monitoring for ``localMongoClient`` and begin capturing
218124
events. Note that some events may need to be filtered out if the driver
219-
uses global listeners or reports internal commands (e.g. ``isMaster``,
220-
authentication).
125+
uses global listeners or reports internal commands (e.g. ``hello``, legacy
126+
hello, authentication).
221127

222128
- For each element in the ``operations`` array:
223129

@@ -310,9 +216,13 @@ Prose Tests
310216

311217
The following tests have not yet been automated, but MUST still be tested.
312218

313-
"errInfo" is propagated
314-
-----------------------
315-
Test that a writeConcernError "errInfo" is propagated to the user in whatever way is idiomatic to the driver (exception, error object, etc.). Using a 4.0+ server, set the following failpoint:
219+
1. WriteConcernError.details exposes writeConcernError.errInfo
220+
--------------------------------------------------------------
221+
222+
Test that ``writeConcernError.errInfo`` in a command response is propagated as
223+
``WriteConcernError.details`` (or equivalent) in the driver.
224+
225+
Using a 4.0+ server, set the following failpoint:
316226

317227
.. code:: javascript
318228
@@ -335,4 +245,34 @@ Test that a writeConcernError "errInfo" is propagated to the user in whatever wa
335245
},
336246
"mode": { "times": 1 }
337247
}
338-
Then, perform an insert on the same database. Assert that an error occurs and that the "errInfo" is accessible and matches the one set in the failpoint.
248+
249+
Then, perform an insert operation and assert that a WriteConcernError occurs and
250+
that its ``details`` property is both accessible and matches the ``errInfo``
251+
object from the failpoint.
252+
253+
2. WriteError.details exposes writeErrors[].errInfo
254+
---------------------------------------------------
255+
256+
Test that ``writeErrors[].errInfo`` in a command response is propagated as
257+
``WriteError.details`` (or equivalent) in the driver.
258+
259+
Using a 5.0+ server, create a collection with
260+
`document validation <https://docs.mongodb.com/manual/core/schema-validation/>`_
261+
like so:
262+
263+
.. code:: javascript
264+
265+
{
266+
"create": "test",
267+
"validator": {
268+
"x": { $type: "string" }
269+
}
270+
}
271+
272+
Enable `command monitoring <../../command-monitoring/command-monitoring.rst>`_
273+
to observe CommandSucceededEvents. Then, insert an invalid document (e.g.
274+
``{x: 1}``) and assert that a WriteError occurs, that its code is ``121``
275+
(i.e. DocumentValidationFailure), and that its ``details`` property is
276+
accessible. Additionally, assert that a CommandSucceededEvent was observed and
277+
that the ``writeErrors[0].errInfo`` field in the response document matches the
278+
WriteError's ``details`` property.

0 commit comments

Comments
 (0)