Skip to content

Commit 73c323d

Browse files
authored
RUST-1567 Sync CLAM write concern error test (#830)
1 parent 89f9345 commit 73c323d

File tree

4 files changed

+296
-1
lines changed

4 files changed

+296
-1
lines changed

src/test/spec/command_monitoring/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::test::LOCK;
22

33
use super::{run_spec_test_with_path, run_unified_format_test_filtered, unified_runner::TestCase};
44

5-
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
5+
#[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))]
66
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
77
async fn command_monitoring_unified() {
88
let _guard = LOCK.run_exclusively().await;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
.. role:: javascript(code)
2+
:language: javascript
3+
4+
==============================
5+
Command Logging and Monitoring
6+
==============================
7+
8+
.. contents::
9+
10+
--------
11+
12+
Testing
13+
=======
14+
15+
Automated Tests
16+
^^^^^^^^^^^^^^^
17+
There are tests in the `Unified Test Format <../../unified-test-format/unified-test-format.rst>`__ for both logging and
18+
monitoring in `/logging <./logging>`_ and `/monitoring <./monitoring>`_, respectively. Drivers MUST run the logging
19+
tests with their max document length setting (as described in the
20+
`logging specification <../../logging/logging.rst#configurable-max-document-length>`__) set to a large value e.g. 10,000;
21+
this is necessary in order for the driver to emit the full server reply (and to allow matching against that reply) on
22+
certain MongoDB versions and topologies.
23+
24+
Prose Tests
25+
^^^^^^^^^^^
26+
Drivers MUST implement the following logging prose tests. These tests require the ability to capture log message data in a
27+
structured form as described in the
28+
`Unified Test Format specification <../../unified-test-format/unified-test-format.rst#expectedLogMessage>`__.
29+
30+
Note: the following tests mention string "length"; this refers to length in terms of whatever unit the driver has chosen
31+
to support for specifying max document length as discussed in the
32+
`logging specification <../../logging/logging.rst#configurable-max-document-length>`__.
33+
34+
*Test 1: Default truncation limit*
35+
36+
1. Configure logging with a minimum severity level of "debug" for the "command" component. Do not explicitly configure the max document length.
37+
2. Construct an array ``docs`` containing the document ``{"x" : "y"}`` repeated 100 times.
38+
3. Insert ``docs`` to a collection via ``insertMany``.
39+
4. Inspect the resulting "command started" log message and assert that the "command" value is a string of length 1000 + (length of trailing ellipsis).
40+
5. Inspect the resulting "command succeeded" log message and assert that the "reply" value is a string of length <= 1000 + (length of trailing ellipsis).
41+
6. Run ``find()`` on the collection where the document was inserted.
42+
7. Inspect the resulting "command succeeded" log message and assert that the reply is a string of length 1000 + (length of trailing ellipsis).
43+
44+
*Test 2: Explicitly configured truncation limit*
45+
46+
1. Configure logging with a minimum severity level of "debug" for the "command" component. Set the max document length to 5.
47+
2. Run the command ``{"hello": true}``.
48+
3. Inspect the resulting "command started" log message and assert that the "command" value is a string of length 5 + (length of trailing ellipsis).
49+
4. Inspect the resulting "command succeeded" log message and assert that the "reply" value is a string of length 5 + (length of trailing ellipsis).
50+
5. If the driver attaches raw server responses to failures and can access these via log messages to assert on, run the command
51+
``{"notARealCommand": true}``. Inspect the resulting "command failed" log message and confirm that the server error is
52+
a string of length 5 + (length of trailing ellipsis).
53+
54+
*Test 3: Truncation with multi-byte codepoints*
55+
56+
A specific test case is not provided here due to the allowed variations in truncation logic as well as varying extended JSON whitespace usage.
57+
Drivers MUST write language-specific tests that confirm truncation of commands, replies, and (if applicable) server responses included in error
58+
messages work as expected when the data being truncated includes multi-byte Unicode codepoints.
59+
If the driver uses anything other than Unicode codepoints as the unit for max document length, there also MUST be tests confirming that cases
60+
where the max length falls in the middle of a multi-byte codepoint are handled gracefully.
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
{
2+
"description": "writeConcernError",
3+
"schemaVersion": "1.13",
4+
"runOnRequirements": [
5+
{
6+
"minServerVersion": "4.1.0",
7+
"topologies": [
8+
"replicaset"
9+
],
10+
"serverless": "forbid"
11+
}
12+
],
13+
"createEntities": [
14+
{
15+
"client": {
16+
"id": "client",
17+
"observeEvents": [
18+
"commandStartedEvent",
19+
"commandSucceededEvent",
20+
"commandFailedEvent"
21+
]
22+
}
23+
},
24+
{
25+
"database": {
26+
"id": "database",
27+
"client": "client",
28+
"databaseName": "command-monitoring-tests"
29+
}
30+
},
31+
{
32+
"collection": {
33+
"id": "collection",
34+
"database": "database",
35+
"collectionName": "test"
36+
}
37+
}
38+
],
39+
"initialData": [
40+
{
41+
"collectionName": "test",
42+
"databaseName": "command-monitoring-tests",
43+
"documents": [
44+
{
45+
"_id": 1,
46+
"x": 11
47+
}
48+
]
49+
}
50+
],
51+
"tests": [
52+
{
53+
"description": "A retryable write with write concern errors publishes success event",
54+
"operations": [
55+
{
56+
"name": "failPoint",
57+
"object": "testRunner",
58+
"arguments": {
59+
"client": "client",
60+
"failPoint": {
61+
"configureFailPoint": "failCommand",
62+
"mode": {
63+
"times": 1
64+
},
65+
"data": {
66+
"failCommands": [
67+
"insert"
68+
],
69+
"writeConcernError": {
70+
"code": 91,
71+
"errorLabels": [
72+
"RetryableWriteError"
73+
]
74+
}
75+
}
76+
}
77+
}
78+
},
79+
{
80+
"name": "insertOne",
81+
"object": "collection",
82+
"arguments": {
83+
"document": {
84+
"_id": 2,
85+
"x": 22
86+
}
87+
}
88+
}
89+
],
90+
"expectEvents": [
91+
{
92+
"client": "client",
93+
"events": [
94+
{
95+
"commandStartedEvent": {
96+
"command": {
97+
"insert": "test",
98+
"documents": [
99+
{
100+
"_id": 2,
101+
"x": 22
102+
}
103+
],
104+
"ordered": true
105+
},
106+
"commandName": "insert",
107+
"databaseName": "command-monitoring-tests"
108+
}
109+
},
110+
{
111+
"commandSucceededEvent": {
112+
"reply": {
113+
"ok": 1,
114+
"n": 1,
115+
"writeConcernError": {
116+
"code": 91,
117+
"errorLabels": [
118+
"RetryableWriteError"
119+
]
120+
}
121+
},
122+
"commandName": "insert"
123+
}
124+
},
125+
{
126+
"commandStartedEvent": {
127+
"command": {
128+
"insert": "test",
129+
"documents": [
130+
{
131+
"_id": 2,
132+
"x": 22
133+
}
134+
],
135+
"ordered": true
136+
},
137+
"commandName": "insert",
138+
"databaseName": "command-monitoring-tests"
139+
}
140+
},
141+
{
142+
"commandSucceededEvent": {
143+
"reply": {
144+
"ok": 1,
145+
"n": 1
146+
},
147+
"commandName": "insert"
148+
}
149+
}
150+
]
151+
}
152+
]
153+
}
154+
]
155+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
description: "writeConcernError"
2+
schemaVersion: "1.13"
3+
runOnRequirements:
4+
-
5+
minServerVersion: 4.1.0
6+
topologies:
7+
- replicaset
8+
serverless: "forbid"
9+
10+
createEntities:
11+
- client:
12+
id: &client client
13+
observeEvents:
14+
- commandStartedEvent
15+
- commandSucceededEvent
16+
- commandFailedEvent
17+
- database:
18+
id: &database database
19+
client: *client
20+
databaseName: &databaseName command-monitoring-tests
21+
- collection:
22+
id: &collection collection
23+
database: *database
24+
collectionName: &collectionName test
25+
26+
initialData:
27+
- collectionName: *collectionName
28+
databaseName: *databaseName
29+
documents:
30+
- { _id: 1, x: 11 }
31+
32+
tests:
33+
- description: "A retryable write with write concern errors publishes success event"
34+
operations:
35+
- name: failPoint
36+
object: testRunner
37+
arguments:
38+
client: *client
39+
failPoint:
40+
configureFailPoint: failCommand
41+
mode: { times: 1 }
42+
data:
43+
failCommands: [ insert ]
44+
writeConcernError:
45+
code: 91 # ShutdownInProgress
46+
errorLabels: [RetryableWriteError]
47+
- name: insertOne
48+
object: *collection
49+
arguments:
50+
document: { _id: 2, x: 22 }
51+
expectEvents:
52+
- client: *client
53+
events:
54+
- commandStartedEvent:
55+
command:
56+
insert: *collectionName
57+
documents:
58+
- { _id: 2, x: 22 }
59+
ordered: true
60+
commandName: insert
61+
databaseName: *databaseName
62+
- commandSucceededEvent:
63+
reply:
64+
ok: 1
65+
n: 1
66+
writeConcernError: { code: 91, errorLabels: [ "RetryableWriteError" ] }
67+
commandName: insert
68+
- commandStartedEvent:
69+
command:
70+
insert: *collectionName
71+
documents:
72+
- { _id: 2, x: 22 }
73+
ordered: true
74+
commandName: insert
75+
databaseName: *databaseName
76+
- commandSucceededEvent:
77+
reply:
78+
ok: 1
79+
n: 1
80+
commandName: insert

0 commit comments

Comments
 (0)