Skip to content

Commit 192088b

Browse files
committed
minor: add command monitoring tests
1 parent 967ca43 commit 192088b

21 files changed

+2579
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
.. role:: javascript(code)
2+
:language: javascript
3+
4+
==================
5+
Command Monitoring
6+
==================
7+
8+
.. contents::
9+
10+
--------
11+
12+
Testing
13+
=======
14+
15+
Tests are provided in YML and JSON format to assert proper upconversion of commands.
16+
17+
Database and Collection Names
18+
-----------------------------
19+
20+
The collection under test is specified in each test file with the fields
21+
``database_name`` and ``collection_name``.
22+
23+
Data
24+
----
25+
26+
The ``data`` at the beginning of each test file is the data that should exist in the
27+
collection under test before each test run.
28+
29+
Expectations
30+
------------
31+
32+
Fake Placeholder Values
33+
```````````````````````
34+
35+
When an attribute in an expectation contains the value ``"42"``, ``42`` or ``""``, this is a fake
36+
placeholder value indicating that a special case MUST be tested that could not be
37+
expressed in a YAML or JSON test. These cases are as follows:
38+
39+
Cursor Matching
40+
^^^^^^^^^^^^^^^
41+
42+
When encountering a ``cursor`` or ``getMore`` value of ``"42"`` in a test, the driver MUST assert
43+
that the values are equal to each other and greater than zero.
44+
45+
Errors
46+
^^^^^^
47+
48+
For write errors, ``code`` values of ``42`` MUST assert that the value is present and
49+
greater than zero. ``errmsg`` values of ``""`` MUST assert that the value is not empty
50+
(a string of length greater than 1).
51+
52+
OK Values
53+
^^^^^^^^^
54+
55+
The server is inconsistent on whether the ok values returned are integers or doubles so
56+
for simplicity the tests specify all expected values as doubles. Server 'ok' values of
57+
integers MUST be converted to doubles for comparison with the expected values.
58+
59+
Additional Values
60+
`````````````````
61+
62+
The expected events provide the minimum data that is required and can be tested. It is
63+
possible for more values to be present in the events, such as extra data provided when
64+
using sharded clusters or ``nModified`` field in updates. The driver MUST assert the
65+
expected data is present and also MUST allow for additional data to be present as well
66+
at the top level of the command document or reply document.
67+
68+
For example, say the client sends a causally-consistent "distinct" command with
69+
readConcern level "majority", like::
70+
71+
{
72+
"distinct": "collection",
73+
"key": "key",
74+
"readConcern":{
75+
"afterClusterTime": {"$timestamp":{"t":1522336030,"i":1}},
76+
"level":"majority"
77+
},
78+
"$clusterTime": {
79+
"clusterTime": { "$timestamp": { "i": 1, "t": 1522335530 } },
80+
"signature": {
81+
"hash": { "$binary": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type": "00" },
82+
"keyId": { "$numberLong": "0" }
83+
}
84+
},
85+
"lsid": {
86+
"id": { "$binary": "RaigP3oASqu+galPvRAfcg==", "$type": "04" }
87+
}
88+
}
89+
90+
Then it would pass a command-started event like the following YAML, because the
91+
fields not mentioned in the YAML are ignored::
92+
93+
command:
94+
distinct: collection
95+
key: key
96+
97+
However, if there are fields in command subdocuments that are not mentioned in
98+
the YAML, then the command does *not* pass the test::
99+
100+
command:
101+
distinct: collection
102+
key: key
103+
# Fails because the expected readConcern has no "afterClusterTime".
104+
readConcern:
105+
level: majority
106+
107+
Ignoring Tests Based On Server Version or Topology Type
108+
```````````````````````````````````````````````````````
109+
110+
Due to variations in server behavior, some tests may not be valid and MUST NOT be run on
111+
certain server versions or topology types. These tests are indicated with any of the
112+
following fields, which will be optionally provided at the ``description`` level of each
113+
test:
114+
115+
- ``ignore_if_server_version_greater_than`` (optional): If specified, the test MUST be
116+
skipped if the minor version of the server is greater than this minor version. The
117+
server's patch version MUST NOT be considered. For example, a value of ``3.0`` implies
118+
that the test can run on server version ``3.0.15`` but not ``3.1.0``.
119+
120+
- ``ignore_if_server_version_less_than`` (optional): If specified, the test MUST be
121+
skipped if the minor version of the server is less than this minor version. The
122+
server's patch version MUST NOT be considered. For example, a value of ``3.2`` implies
123+
that the test can run on server version ``3.2.0`` but not ``3.0.15``.
124+
125+
- ``ignore_if_topology_type`` (optional): An array of server topologies for which the test
126+
MUST be skipped. Valid topologies are "single", "replicaset", and "sharded".
127+
128+
Tests that have none of these fields MUST be run on all supported server versions.
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
{
2+
"data": [
3+
{
4+
"_id": 1,
5+
"x": 11
6+
},
7+
{
8+
"_id": 2,
9+
"x": 22
10+
},
11+
{
12+
"_id": 3,
13+
"x": 33
14+
}
15+
],
16+
"collection_name": "test",
17+
"database_name": "command-monitoring-tests",
18+
"tests": [
19+
{
20+
"description": "A successful mixed bulk write",
21+
"operation": {
22+
"name": "bulkWrite",
23+
"arguments": {
24+
"requests": [
25+
{
26+
"name": "insertOne",
27+
"arguments": {
28+
"document": {
29+
"_id": 4,
30+
"x": 44
31+
}
32+
}
33+
},
34+
{
35+
"name": "updateOne",
36+
"arguments": {
37+
"filter": {
38+
"_id": 3
39+
},
40+
"update": {
41+
"$set": {
42+
"x": 333
43+
}
44+
}
45+
}
46+
}
47+
]
48+
}
49+
},
50+
"expectations": [
51+
{
52+
"command_started_event": {
53+
"command": {
54+
"insert": "test",
55+
"documents": [
56+
{
57+
"_id": 4,
58+
"x": 44
59+
}
60+
],
61+
"ordered": true
62+
},
63+
"command_name": "insert",
64+
"database_name": "command-monitoring-tests"
65+
}
66+
},
67+
{
68+
"command_succeeded_event": {
69+
"reply": {
70+
"ok": 1,
71+
"n": 1
72+
},
73+
"command_name": "insert"
74+
}
75+
},
76+
{
77+
"command_started_event": {
78+
"command": {
79+
"update": "test",
80+
"updates": [
81+
{
82+
"q": {
83+
"_id": 3
84+
},
85+
"u": {
86+
"$set": {
87+
"x": 333
88+
}
89+
}
90+
}
91+
],
92+
"ordered": true
93+
},
94+
"command_name": "update",
95+
"database_name": "command-monitoring-tests"
96+
}
97+
},
98+
{
99+
"command_succeeded_event": {
100+
"reply": {
101+
"ok": 1,
102+
"n": 1
103+
},
104+
"command_name": "update"
105+
}
106+
}
107+
]
108+
}
109+
]
110+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
data:
2+
- { _id: 1, x: 11 }
3+
- { _id: 2, x: 22 }
4+
- { _id: 3, x: 33 }
5+
6+
collection_name: &collection_name "test"
7+
database_name: &database_name "command-monitoring-tests"
8+
9+
tests:
10+
-
11+
description: "A successful mixed bulk write"
12+
operation:
13+
name: "bulkWrite"
14+
arguments:
15+
requests:
16+
- name: "insertOne"
17+
arguments:
18+
document: { _id: 4, x: 44 }
19+
- name: "updateOne"
20+
arguments:
21+
filter: { _id: 3 }
22+
update: { $set: { x: 333 } }
23+
expectations:
24+
-
25+
command_started_event:
26+
command:
27+
insert: *collection_name
28+
documents:
29+
- { _id: 4, x: 44 }
30+
ordered: true
31+
command_name: "insert"
32+
database_name: *database_name
33+
-
34+
command_succeeded_event:
35+
reply: { ok: 1.0, n: 1 }
36+
command_name: "insert"
37+
-
38+
command_started_event:
39+
command:
40+
update: *collection_name
41+
updates:
42+
- { q: {_id: 3 }, u: { $set: { x: 333 } } }
43+
ordered: true
44+
command_name: "update"
45+
database_name: *database_name
46+
-
47+
command_succeeded_event:
48+
reply: { ok: 1.0, n: 1 }
49+
command_name: "update"

0 commit comments

Comments
 (0)