Skip to content

Commit dae2dee

Browse files
authored
Convert CRUD v2 tests to unified, sync BSON corpus and poc-transactions tests (#686)
* GODRIVER-1970 Convert CRUD v2 to unified * GODRIVER-1870 Sync tests related to allowing dots and dollars
1 parent 4adb6d7 commit dae2dee

File tree

233 files changed

+22324
-10340
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

233 files changed

+22324
-10340
lines changed

data/bson-corpus/document.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,26 @@
1717
"description": "Single-character key subdoc",
1818
"canonical_bson": "160000000378000E0000000261000200000062000000",
1919
"canonical_extjson": "{\"x\" : {\"a\" : \"b\"}}"
20+
},
21+
{
22+
"description": "Dollar-prefixed key in sub-document",
23+
"canonical_bson": "170000000378000F000000022461000200000062000000",
24+
"canonical_extjson": "{\"x\" : {\"$a\" : \"b\"}}"
25+
},
26+
{
27+
"description": "Dollar as key in sub-document",
28+
"canonical_bson": "160000000378000E0000000224000200000061000000",
29+
"canonical_extjson": "{\"x\" : {\"$\" : \"a\"}}"
30+
},
31+
{
32+
"description": "Dotted key in sub-document",
33+
"canonical_bson": "180000000378001000000002612E62000200000063000000",
34+
"canonical_extjson": "{\"x\" : {\"a.b\" : \"c\"}}"
35+
},
36+
{
37+
"description": "Dot as key in sub-document",
38+
"canonical_bson": "160000000378000E000000022E000200000061000000",
39+
"canonical_extjson": "{\"x\" : {\".\" : \"a\"}}"
2040
}
2141
],
2242
"decodeErrors": [

data/bson-corpus/top.json

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,24 @@
33
"bson_type": "0x00",
44
"valid": [
55
{
6-
"description": "Document with keys that start with $",
6+
"description": "Dollar-prefixed key in top-level document",
77
"canonical_bson": "0F00000010246B6579002A00000000",
88
"canonical_extjson": "{\"$key\": {\"$numberInt\": \"42\"}}"
9+
},
10+
{
11+
"description": "Dollar as key in top-level document",
12+
"canonical_bson": "0E00000002240002000000610000",
13+
"canonical_extjson": "{\"$\": \"a\"}"
14+
},
15+
{
16+
"description": "Dotted key in top-level document",
17+
"canonical_bson": "1000000002612E620002000000630000",
18+
"canonical_extjson": "{\"a.b\": \"c\"}"
19+
},
20+
{
21+
"description": "Dot as key in top-level document",
22+
"canonical_bson": "0E000000022E0002000000610000",
23+
"canonical_extjson": "{\".\": \"a\"}"
924
}
1025
],
1126
"decodeErrors": [
@@ -69,11 +84,11 @@
6984
"parseErrors": [
7085
{
7186
"description" : "Bad $regularExpression (extra field)",
72-
"string" : "{\"a\" : \"$regularExpression\": {\"pattern\": \"abc\", \"options\": \"\", \"unrelated\": true}}}"
87+
"string" : "{\"a\" : {\"$regularExpression\": {\"pattern\": \"abc\", \"options\": \"\", \"unrelated\": true}}}"
7388
},
7489
{
7590
"description" : "Bad $regularExpression (missing options field)",
76-
"string" : "{\"a\" : \"$regularExpression\": {\"pattern\": \"abc\"}}}"
91+
"string" : "{\"a\" : {\"$regularExpression\": {\"pattern\": \"abc\"}}}"
7792
},
7893
{
7994
"description": "Bad $regularExpression (pattern is number, not string)",
@@ -85,7 +100,7 @@
85100
},
86101
{
87102
"description" : "Bad $regularExpression (missing pattern field)",
88-
"string" : "{\"a\" : \"$regularExpression\": {\"options\":\"ix\"}}}"
103+
"string" : "{\"a\" : {\"$regularExpression\": {\"options\":\"ix\"}}}"
89104
},
90105
{
91106
"description": "Bad $oid (number, not string)",
@@ -151,6 +166,10 @@
151166
"description": "Bad $code (type is number, not string)",
152167
"string": "{\"a\" : {\"$code\" : 42}}"
153168
},
169+
{
170+
"description": "Bad $code (type is number, not string) when $scope is also present",
171+
"string": "{\"a\" : {\"$code\" : 42, \"$scope\" : {}}}"
172+
},
154173
{
155174
"description": "Bad $code (extra field)",
156175
"string": "{\"a\" : {\"$code\" : \"\", \"unrelated\": true}}"

data/crud/README.rst

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

22-
This document describes two legacy formats for CRUD tests: legacy-v1, which dates back
23-
to the first version of the CRUD specification, and legacy-v2, which was an update to
24-
the initial format. New CRUD tests should be written in the `unified test format <../../../../unified-test-format/unified-test-format.rst>`_
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>`_
2525
and placed under ``unified/``. Until such time that all original tests have been ported
2626
to the unified test format, tests in each format will be grouped in their own subdirectory:
2727

2828
- ``v1/``: Legacy-v1 format tests
29-
- ``v2/``: Legacy-v2 format tests
3029
- ``unified/``: Tests using the `unified test format <../../../../unified-test-format/unified-test-format.rst>`_
3130

3231
Since some drivers may not have a unified test runner capable of executing tests
33-
in all three 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
3433
drivers to sync and feed test files to different test runners.
3534

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

@@ -173,8 +74,8 @@ messages into the bulk write exception's top-level message.
17374
Test Runner Implementation
17475
==========================
17576

176-
This section provides guidance for implementing a test runner for legacy-v1 and
177-
legacy-v2 tests. See the `unified test format spec <../../../../unified-test-format/unified-test-format.rst>`_ for how to run tests under
77+
This section provides guidance for implementing a test runner for legacy-v1
78+
tests. See the `unified test format spec <../../../../unified-test-format/unified-test-format.rst>`_ for how to run tests under
17879
``unified/``.
17980

18081
Before running the tests:
@@ -219,8 +120,8 @@ For each test file:
219120

220121
- Activate command monitoring for ``localMongoClient`` and begin capturing
221122
events. Note that some events may need to be filtered out if the driver
222-
uses global listeners or reports internal commands (e.g. ``isMaster``,
223-
authentication).
123+
uses global listeners or reports internal commands (e.g. ``hello``, legacy
124+
hello, authentication).
224125

225126
- For each element in the ``operations`` array:
226127

@@ -313,9 +214,13 @@ Prose Tests
313214

314215
The following tests have not yet been automated, but MUST still be tested.
315216

316-
"errInfo" is propagated
317-
-----------------------
318-
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:
217+
1. WriteConcernError.details exposes writeConcernError.errInfo
218+
--------------------------------------------------------------
219+
220+
Test that ``writeConcernError.errInfo`` in a command response is propagated as
221+
``WriteConcernError.details`` (or equivalent) in the driver.
222+
223+
Using a 4.0+ server, set the following failpoint:
319224

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

0 commit comments

Comments
 (0)