Skip to content

Commit 3f7dd57

Browse files
author
iwysiu
committed
GODRIVER-919 add ability to specify a pipeline to an update command
Change-Id: Id6d6ab42b2287190e856654ec54880d5e4d5df5c
1 parent cfec8bd commit 3f7dd57

30 files changed

+710
-129
lines changed

data/command-monitoring/README.rst

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.

data/command-monitoring/bulkWrite.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@
8686
"$set": {
8787
"x": 333
8888
}
89-
},
90-
"upsert": false,
91-
"multi": false
89+
}
9290
}
9391
],
9492
"ordered": true

data/command-monitoring/bulkWrite.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ tests:
3939
command:
4040
update: *collection_name
4141
updates:
42-
- { q: {_id: 3 }, u: { $set: { x: 333 } }, upsert: false, multi: false }
42+
- { q: {_id: 3 }, u: { $set: { x: 333 } } }
4343
ordered: true
4444
command_name: "update"
4545
database_name: *database_name

data/command-monitoring/updateMany.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@
5151
"x": 1
5252
}
5353
},
54-
"multi": true,
55-
"upsert": false
54+
"multi": true
5655
}
5756
]
5857
},
@@ -106,8 +105,7 @@
106105
"x": 1
107106
}
108107
},
109-
"multi": true,
110-
"upsert": false
108+
"multi": true
111109
}
112110
]
113111
},

data/command-monitoring/updateMany.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ tests:
2727
q: { _id: { $gt: 1 }}
2828
u: { $inc: { x: 1 }}
2929
multi: true
30-
upsert: false
3130
command_name: "update"
3231
database_name: *database_name
3332
-
@@ -54,7 +53,6 @@ tests:
5453
q: { _id: { $gt: 1 }}
5554
u: { $nothing: { x: 1 }}
5655
multi: true
57-
upsert: false
5856
command_name: "update"
5957
database_name: *database_name
6058
-

data/command-monitoring/updateOne.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@
5050
"$inc": {
5151
"x": 1
5252
}
53-
},
54-
"multi": false,
55-
"upsert": false
53+
}
5654
}
5755
]
5856
},
@@ -103,7 +101,6 @@
103101
"x": 1
104102
}
105103
},
106-
"multi": false,
107104
"upsert": true
108105
}
109106
]
@@ -163,9 +160,7 @@
163160
"$nothing": {
164161
"x": 1
165162
}
166-
},
167-
"multi": false,
168-
"upsert": false
163+
}
169164
}
170165
]
171166
},

data/command-monitoring/updateOne.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ tests:
2626
-
2727
q: { _id: { $gt: 1 }}
2828
u: { $inc: { x: 1 }}
29-
multi: false
30-
upsert: false
3129
command_name: "update"
3230
database_name: *database_name
3331
-
@@ -54,7 +52,6 @@ tests:
5452
-
5553
q: { _id: 4 }
5654
u: { $inc: { x: 1 } }
57-
multi: false
5855
upsert: true
5956
command_name: "update"
6057
database_name: *database_name
@@ -81,8 +78,6 @@ tests:
8178
-
8279
q: { _id: { $gt: 1 }}
8380
u: { $nothing: { x: 1 }}
84-
multi: false
85-
upsert: false
8681
command_name: "update"
8782
database_name: *database_name
8883
-

data/crud/v2/aggregate-merge.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{
2+
"runOn": [
3+
{
4+
"minServerVersion": "4.2.0"
5+
}
6+
],
27
"data": [
38
{
49
"_id": 1,
@@ -13,7 +18,6 @@
1318
"x": 33
1419
}
1520
],
16-
"minServerVersion": "4.2.0",
1721
"collection_name": "test_aggregate_merge",
1822
"tests": [
1923
{
@@ -408,4 +412,4 @@
408412
}
409413
}
410414
]
411-
}
415+
}

data/crud/v2/aggregate-merge.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
data:
2-
- { _id: 1, x: 11 }
3-
- { _id: 2, x: 22 }
4-
- { _id: 3, x: 33 }
1+
runOn:
2+
-
3+
minServerVersion: "4.2.0"
54

6-
minServerVersion: '4.2.0'
5+
data:
6+
- { _id: 1, x: 11 }
7+
- { _id: 2, x: 22 }
8+
- { _id: 3, x: 33 }
79

810
collection_name: &collection_name 'test_aggregate_merge'
911

@@ -98,4 +100,4 @@ tests:
98100
aggregate: *collection_name
99101
pipeline: *pipeline
100102
readConcern: { level: "available" }
101-
outcome: *outcome
103+
outcome: *outcome

data/crud/v2/aggregate-out-readConcern.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
{
2+
"runOn": [
3+
{
4+
"minServerVersion": "4.1.0",
5+
"topology": [
6+
"replicaset",
7+
"sharded"
8+
]
9+
}
10+
],
211
"data": [
312
{
413
"_id": 1,
@@ -13,7 +22,6 @@
1322
"x": 33
1423
}
1524
],
16-
"minServerVersion": "4.1",
1725
"collection_name": "test_aggregate_out_readconcern",
1826
"tests": [
1927
{
@@ -374,4 +382,4 @@
374382
]
375383
}
376384
]
377-
}
385+
}

0 commit comments

Comments
 (0)