|
2 | 2 |
|
3 | 3 | ## Introduction
|
4 | 4 |
|
5 |
| -The YAML and JSON files in this directory tree are platform-independent tests that drivers can use to prove their |
6 |
| -conformance to the CRUD spec. |
| 5 | +The YAML and JSON files in this directory are platform-independent tests meant to exercise a driver's implementation of |
| 6 | +the CRUD specification. These tests utilize the [Unified Test Format](../../unified-test-format/unified-test-format.md). |
7 | 7 |
|
8 |
| -Running these integration tests will require a running MongoDB server or cluster with server versions 2.6.0 or later. |
9 |
| -Some tests have specific server version requirements as noted by the `runOn` section, if provided. |
10 |
| - |
11 |
| -### Subdirectories for Test Formats |
12 |
| - |
13 |
| -This document describes a legacy format for CRUD tests: legacy-v1, which dates back to the first version of the CRUD |
14 |
| -specification. New CRUD tests should be written in the |
15 |
| -[unified test format](../../unified-test-format/unified-test-format.md) and placed under `unified/`. Until such time |
16 |
| -that all original tests have been ported to the unified test format, tests in each format will be grouped in their own |
17 |
| -subdirectory: |
18 |
| - |
19 |
| -- `v1/`: Legacy-v1 format tests |
20 |
| -- `unified/`: Tests using the [unified test format](../../unified-test-format/unified-test-format.md) |
21 |
| - |
22 |
| -Since some drivers may not have a unified test runner capable of executing tests in all two formats, segregating tests |
23 |
| -in this manner will make it easier for drivers to sync and feed test files to different test runners. |
24 |
| - |
25 |
| -### Legacy-v1 Test Format for Single Operations |
26 |
| - |
27 |
| -*Note: this section pertains to test files in the "v1" directory.* |
28 |
| - |
29 |
| -The test format above supports both multiple operations and APM expectations, and is consistent with the formats used by |
30 |
| -other specifications. Previously, the CRUD spec tests used a simplified format that only allowed for executing a single |
31 |
| -operation. Notable differences from the legacy-v2 format are as follows: |
32 |
| - |
33 |
| -- Instead of a `tests[i].operations` array, a single operation was defined as a document in `tests[i].operation`. That |
34 |
| - document consisted of only the `name`, `arguments`, and an optional `object` field. |
35 |
| -- Instead of `error` and `result` fields within each element in the `tests[i].operations` array, the single operation's |
36 |
| - error and result were defined under the `tests[i].outcome.error` and `tests[i].outcome.result` fields. |
37 |
| -- Instead of a top-level `runOn` field, server requirements are denoted by separate top-level `minServerVersion`, |
38 |
| - `maxServerVersion`, and `serverless` fields. The minimum server version is an inclusive lower bound for running the |
39 |
| - test. The maximum server version is an exclusive upper bound for running the test. If a field is not present, it |
40 |
| - should be assumed that there is no corresponding bound on the required server version. The `serverless` requirement |
41 |
| - behaves the same as the `serverless` field of the |
42 |
| - [unified test format's runOnRequirement](../../unified-test-format/unified-test-format.md#runonrequirement). |
43 |
| - |
44 |
| -The legacy-v1 format should not conflict with the newer, multi-operation format used by other specs (e.g. Transactions). |
45 |
| -It is possible to create a unified test runner capable of executing both legacy formats (as some drivers do). |
46 |
| - |
47 |
| -## Error Assertions for Bulk Write Operations |
48 |
| - |
49 |
| -When asserting errors (e.g. `errorContains`, `errorCodeName`) for bulk write operations, the test harness should inspect |
50 |
| -the `writeConcernError` and/or `writeErrors` properties of the bulk write exception. This may not be needed for |
51 |
| -`errorContains` if a driver concatenates all write and write concern error messages into the bulk write exception's |
52 |
| -top-level message. |
53 |
| - |
54 |
| -## Test Runner Implementation |
55 |
| - |
56 |
| -This section provides guidance for implementing a test runner for legacy-v1 tests. See the |
57 |
| -[unified test format spec](../../unified-test-format/unified-test-format.md) for how to run tests under `unified/`. |
58 |
| - |
59 |
| -Before running the tests: |
60 |
| - |
61 |
| -- Create a global MongoClient (`globalMongoClient`) and connect to the server. This client will be used for executing |
62 |
| - meta operations, such as checking server versions and preparing data fixtures. |
63 |
| - |
64 |
| -For each test file: |
65 |
| - |
66 |
| -- Using `globalMongoClient`, check that the current server version satisfies one of the configurations provided in the |
67 |
| - top-level `runOn` field in the test file (if applicable). If the requirements are not satisfied, the test file should |
68 |
| - be skipped. |
69 |
| -- Determine the collection and database under test, utilizing the top-level `collection_name` and/or `database_name` |
70 |
| - fields if present. |
71 |
| -- For each element in the `tests` array: |
72 |
| - - Using `globalMongoClient`, ensure that the collection and/or database under test is in a "clean" state, as needed. |
73 |
| - This may be accomplished by dropping the database; however, drivers may also decide to drop individual collections |
74 |
| - as needed (this may be more performant). |
75 |
| - - If the top-level `data` field is present in the test file, insert the corresponding data into the collection under |
76 |
| - test using `globalMongoClient`. |
77 |
| - - If the the `failPoint` field is present, use `globalMongoClient` to configure the fail point on the primary server. |
78 |
| - See [Server Fail Point](../../transactions/tests#server-fail-point) in the Transactions spec test documentation for |
79 |
| - more information. |
80 |
| - - Create a local MongoClient (`localMongoClient`) and connect to the server. This client will be used for executing |
81 |
| - the test case. |
82 |
| - - If `clientOptions` is present, those options should be used to create the client. Drivers MAY merge these options |
83 |
| - atop existing defaults (e.g. reduced `serverSelectionTimeoutMS` value for faster test failures) at their own |
84 |
| - discretion. |
85 |
| - - Activate command monitoring for `localMongoClient` and begin capturing events. Note that some events may need to be |
86 |
| - filtered out if the driver uses global listeners or reports internal commands (e.g. `hello`, legacy hello, |
87 |
| - authentication). |
88 |
| - - For each element in the `operations` array: |
89 |
| - - Using `localMongoClient`, select the appropriate `object` to execute the operation. Default to the collection |
90 |
| - under test if this field is not present. |
91 |
| - - If `collectionOptions` is present, those options should be used to construct the collection object. |
92 |
| - - Given the `name` and `arguments`, execute the operation on the object under test. Capture the result of the |
93 |
| - operation, if any, and observe whether an error occurred. If an error is encountered that includes a result (e.g. |
94 |
| - BulkWriteException), extract the result object. |
95 |
| - - If `error` is present and true, assert that the operation encountered an error. Otherwise, assert that no error |
96 |
| - was encountered. |
97 |
| - - if `result` is present, assert that it matches the operation's result. |
98 |
| - - Deactivate command monitoring for `localMongoClient`. |
99 |
| - - If the `expectations` array is present, assert that the sequence of emitted CommandStartedEvents from executing the |
100 |
| - operation(s) matches the sequence of `command_started_event` objects in the `expectations` array. |
101 |
| - - If the `outcome` field is present, assert the contents of the specified collection using `globalMongoClient`. Note |
102 |
| - the server does not guarantee that documents returned by a find command will be in inserted order. This find MUST |
103 |
| - sort by `{_id:1}`. |
104 |
| - |
105 |
| -### Evaluating Matches |
106 |
| - |
107 |
| -The expected values for results (e.g. `result` for an operation operation, `command_started_event.command`, elements in |
108 |
| -`outcome.data`) are written in [Extended JSON](../../extended-json.rst). Drivers may adopt any of the following |
109 |
| -approaches to comparisons, as long as they are consistent: |
110 |
| - |
111 |
| -- Convert `actual` to Extended JSON and compare to `expected` |
112 |
| -- Convert `expected` and `actual` to BSON, and compare them |
113 |
| -- Convert `expected` and `actual` to native representations, and compare them |
114 |
| - |
115 |
| -#### Extra Fields in Actual Documents |
116 |
| - |
117 |
| -When comparing `actual` and `expected` *documents*, drivers should permit `actual` documents to contain additional |
118 |
| -fields not present in `expected`. For example, the following documents match: |
119 |
| - |
120 |
| -- `expected` is `{ "x": 1 }` |
121 |
| -- `actual` is `{ "_id": { "$oid" : "000000000000000000000001" }, "x": 1 }` |
122 |
| - |
123 |
| -In this sense, `expected` may be a subset of `actual`. It may also be helpful to think of `expected` as a form of query |
124 |
| -criteria. The intention behind this rule is that it is not always feasible for the test to express all fields in the |
125 |
| -expected document(s) (e.g. session and cluster time information in a `command_started_event.command` document). |
126 |
| - |
127 |
| -This rule for allowing extra fields in `actual` only applies for values that correspond to a document. For instance, an |
128 |
| -actual result of `[1, 2, 3, 4]` for a `distinct` operation would not match an expected result of `[1, 2, 3]`. Likewise |
129 |
| -with the `find` operation, this rule would only apply when matching documents *within* the expected result array and |
130 |
| -actual cursor. |
131 |
| - |
132 |
| -Note that in the case of result objects for some CRUD operations, `expected` may condition additional, optional fields |
133 |
| -(see: [Optional Fields in Expected Result Objects](#optional-fields-in-expected-result-objects)). |
134 |
| - |
135 |
| -#### Fields that must NOT be present in Actual Documents |
136 |
| - |
137 |
| -Some command-started events in `expectations` include `null` values for optional fields such as `allowDiskUse`. Tests |
138 |
| -MUST assert that the actual command **omits** any field that has a `null` value in the expected command. |
139 |
| - |
140 |
| -#### Optional Fields in Expected Result Objects |
141 |
| - |
142 |
| -Some `expected` results may include fields that are optional in the CRUD specification, such as `insertedId` (for |
143 |
| -InsertOneResult), `insertedIds` (for InsertManyResult), and `upsertedCount` (for UpdateResult). Drivers that do not |
144 |
| -implement these fields should ignore them when comparing `actual` with `expected`. |
| 8 | +Several prose tests, which are not easily expressed in YAML, are also presented in this file. Those tests will need to |
| 9 | +be manually implemented by each driver. |
145 | 10 |
|
146 | 11 | ## Prose Tests
|
147 | 12 |
|
148 |
| -The following tests have not yet been automated, but MUST still be tested. |
149 |
| - |
150 | 13 | ### 1. WriteConcernError.details exposes writeConcernError.errInfo
|
151 | 14 |
|
152 | 15 | Test that `writeConcernError.errInfo` in a command response is propagated as `WriteConcernError.details` (or equivalent)
|
|
0 commit comments