Skip to content

Commit e74b942

Browse files
RUST-749 Convert CRUD tests to unified format (#410)
1 parent b01351e commit e74b942

File tree

229 files changed

+14614
-9965
lines changed

Some content is hidden

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

229 files changed

+14614
-9965
lines changed

src/selection_criteria.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use std::convert::TryInto;
2-
use std::{collections::HashMap, sync::Arc, time::Duration};
1+
use std::{collections::HashMap, convert::TryInto, sync::Arc, time::Duration};
32

43
use derivative::Derivative;
54
use serde::{de::Error as SerdeError, Deserialize, Deserializer};

src/test/spec/crud_v2.rs renamed to src/test/spec/crud.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use tokio::sync::RwLockWriteGuard;
22

33
use crate::test::{run_spec_test, LOCK};
44

5-
use super::run_v2_test;
5+
use super::run_unified_format_test;
66

7-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
7+
#[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))]
88
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
99
async fn run() {
1010
let _guard: RwLockWriteGuard<()> = LOCK.run_exclusively().await;
11-
run_spec_test(&["crud", "v2"], run_v2_test).await;
11+
run_spec_test(&["crud", "unified"], run_unified_format_test).await;
1212
}

src/test/spec/crud_unified.rs

-15
This file was deleted.

src/test/spec/json/crud/README.rst

+54-117
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
30-
- ``unified/``: Tests using the `unified test format <../../../../unified-test-format/unified-test-format.rst>`_
29+
- ``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

@@ -151,11 +52,13 @@ single operation. Notable differences from the legacy-v2 format are as follows:
15152
fields.
15253

15354
- Instead of a top-level ``runOn`` field, server requirements are denoted by
154-
separate top-level ``minServerVersion`` and ``maxServerVersion`` fields. The
155-
minimum server version is an inclusive lower bound for running the test. The
156-
maximum server version is an exclusive upper bound for running the test. If a
157-
field is not present, it should be assumed that there is no corresponding bound
158-
on the required server version.
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>`_.
15962

16063
The legacy-v1 format should not conflict with the newer, multi-operation format
16164
used by other specs (e.g. Transactions). It is possible to create a unified test
@@ -173,8 +76,8 @@ messages into the bulk write exception's top-level message.
17376
Test Runner Implementation
17477
==========================
17578

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
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
17881
``unified/``.
17982

18083
Before running the tests:
@@ -219,8 +122,8 @@ For each test file:
219122

220123
- Activate command monitoring for ``localMongoClient`` and begin capturing
221124
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).
125+
uses global listeners or reports internal commands (e.g. ``hello``, legacy
126+
hello, authentication).
224127

225128
- For each element in the ``operations`` array:
226129

@@ -313,9 +216,13 @@ Prose Tests
313216

314217
The following tests have not yet been automated, but MUST still be tested.
315218

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:
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:
319226

320227
.. code:: javascript
321228
@@ -338,4 +245,34 @@ Test that a writeConcernError "errInfo" is propagated to the user in whatever wa
338245
},
339246
"mode": { "times": 1 }
340247
}
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.
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.

src/test/spec/json/crud/unified/aggregate-let.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"description": "aggregate-let",
3-
"schemaVersion": "1.0",
3+
"schemaVersion": "1.4",
44
"createEntities": [
55
{
66
"client": {
@@ -310,7 +310,8 @@
310310
"description": "Aggregate to collection with let option",
311311
"runOnRequirements": [
312312
{
313-
"minServerVersion": "5.0"
313+
"minServerVersion": "5.0",
314+
"serverless": "forbid"
314315
}
315316
],
316317
"operations": [

src/test/spec/json/crud/unified/aggregate-let.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
description: "aggregate-let"
22

3-
schemaVersion: "1.0"
3+
schemaVersion: "1.4"
44

55
createEntities:
66
- client:
@@ -126,6 +126,7 @@ tests:
126126
- description: "Aggregate to collection with let option"
127127
runOnRequirements:
128128
- minServerVersion: "5.0"
129+
serverless: "forbid"
129130
operations:
130131
- name: aggregate
131132
object: *collection0

0 commit comments

Comments
 (0)