Skip to content

Commit dfcc3d9

Browse files
authored
test(NODE-4826): update command monitoring tests (#3488)
1 parent d56414f commit dfcc3d9

Some content is hidden

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

49 files changed

+4523
-135
lines changed

test/integration/command-monitoring/command_monitoring.spec.test.ts renamed to test/integration/command-logging-and-monitoring/command_monitoring.spec.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner';
1212
const SKIP = ['A successful unordered bulk write with an unacknowledged write concern'];
1313

1414
describe('Command Monitoring Spec (unified)', () => {
15-
runUnifiedSuite(loadSpecTests(path.join('command-monitoring', 'unified')), ({ description }) =>
16-
SKIP.includes(description) ? `TODO(NODE-4261): support skip reasons in unified tests` : false
15+
runUnifiedSuite(
16+
loadSpecTests(path.join('command-logging-and-monitoring', 'monitoring')),
17+
({ description }) =>
18+
SKIP.includes(description) ? `TODO(NODE-4261): support skip reasons in unified tests` : false
1719
);
1820
});

test/integration/command-monitoring/command_monitoring.test.ts renamed to test/integration/command-logging-and-monitoring/command_monitoring.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,14 @@ describe('Command Monitoring', function () {
366366
{ maxPoolSize: 1, monitorCommands: true }
367367
);
368368

369-
const desiredEvents = ['getnonce'];
369+
const desiredEvents = ['hello'];
370370
client.on('commandStarted', filterForCommands(desiredEvents, started));
371371
client.on('commandSucceeded', filterForCommands(desiredEvents, succeeded));
372372
client.on('commandFailed', filterForCommands(desiredEvents, failed));
373373

374374
return client
375375
.db(this.configuration.db)
376-
.command({ getnonce: true })
376+
.command({ hello: 1, speculativeAuthenticate: { saslStart: 1 } })
377377
.then(r => {
378378
expect(r).to.exist;
379379
expect(started).to.have.length(1);
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: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
{
2+
"description": "command-logging",
3+
"schemaVersion": "1.13",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client",
8+
"observeLogMessages": {
9+
"command": "debug"
10+
}
11+
}
12+
},
13+
{
14+
"database": {
15+
"id": "database",
16+
"client": "client",
17+
"databaseName": "logging-tests"
18+
}
19+
},
20+
{
21+
"collection": {
22+
"id": "collection",
23+
"database": "database",
24+
"collectionName": "logging-tests-collection"
25+
}
26+
}
27+
],
28+
"initialData": [
29+
{
30+
"collectionName": "logging-tests-collection",
31+
"databaseName": "logging-tests",
32+
"documents": [
33+
{
34+
"_id": 1,
35+
"x": 11
36+
}
37+
]
38+
}
39+
],
40+
"tests": [
41+
{
42+
"description": "A successful command",
43+
"operations": [
44+
{
45+
"name": "runCommand",
46+
"object": "database",
47+
"arguments": {
48+
"command": {
49+
"ping": 1
50+
},
51+
"commandName": "ping"
52+
}
53+
}
54+
],
55+
"expectLogMessages": [
56+
{
57+
"client": "client",
58+
"messages": [
59+
{
60+
"level": "debug",
61+
"component": "command",
62+
"data": {
63+
"message": "Command started",
64+
"databaseName": "logging-tests",
65+
"commandName": "ping",
66+
"command": {
67+
"$$matchAsDocument": {
68+
"$$matchAsRoot": {
69+
"ping": 1,
70+
"$db": "logging-tests"
71+
}
72+
}
73+
},
74+
"requestId": {
75+
"$$type": [
76+
"int",
77+
"long"
78+
]
79+
},
80+
"serverHost": {
81+
"$$type": "string"
82+
},
83+
"serverPort": {
84+
"$$type": [
85+
"int",
86+
"long"
87+
]
88+
}
89+
}
90+
},
91+
{
92+
"level": "debug",
93+
"component": "command",
94+
"data": {
95+
"message": "Command succeeded",
96+
"commandName": "ping",
97+
"reply": {
98+
"$$type": "string"
99+
},
100+
"requestId": {
101+
"$$type": [
102+
"int",
103+
"long"
104+
]
105+
},
106+
"serverHost": {
107+
"$$type": "string"
108+
},
109+
"serverPort": {
110+
"$$type": [
111+
"int",
112+
"long"
113+
]
114+
},
115+
"durationMS": {
116+
"$$type": [
117+
"double",
118+
"int",
119+
"long"
120+
]
121+
}
122+
}
123+
}
124+
]
125+
}
126+
]
127+
},
128+
{
129+
"description": "A failed command",
130+
"operations": [
131+
{
132+
"name": "find",
133+
"object": "collection",
134+
"arguments": {
135+
"filter": {
136+
"$or": true
137+
}
138+
},
139+
"expectError": {
140+
"isClientError": false
141+
}
142+
}
143+
],
144+
"expectLogMessages": [
145+
{
146+
"client": "client",
147+
"messages": [
148+
{
149+
"level": "debug",
150+
"component": "command",
151+
"data": {
152+
"message": "Command started",
153+
"databaseName": "logging-tests",
154+
"commandName": "find",
155+
"command": {
156+
"$$type": "string"
157+
},
158+
"requestId": {
159+
"$$type": [
160+
"int",
161+
"long"
162+
]
163+
},
164+
"serverHost": {
165+
"$$type": "string"
166+
},
167+
"serverPort": {
168+
"$$type": [
169+
"int",
170+
"long"
171+
]
172+
}
173+
}
174+
},
175+
{
176+
"level": "debug",
177+
"component": "command",
178+
"data": {
179+
"message": "Command failed",
180+
"commandName": "find",
181+
"failure": {
182+
"$$exists": true
183+
},
184+
"requestId": {
185+
"$$type": [
186+
"int",
187+
"long"
188+
]
189+
},
190+
"serverHost": {
191+
"$$type": "string"
192+
},
193+
"serverPort": {
194+
"$$type": [
195+
"int",
196+
"long"
197+
]
198+
},
199+
"durationMS": {
200+
"$$type": [
201+
"double",
202+
"int",
203+
"long"
204+
]
205+
}
206+
}
207+
}
208+
]
209+
}
210+
]
211+
}
212+
]
213+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
description: "command-logging"
2+
3+
schemaVersion: "1.13"
4+
5+
createEntities:
6+
- client:
7+
id: &client client
8+
observeLogMessages:
9+
command: debug
10+
- database:
11+
id: &database database
12+
client: *client
13+
databaseName: &databaseName logging-tests
14+
- collection:
15+
id: &collection collection
16+
database: *database
17+
collectionName: &collectionName logging-tests-collection
18+
19+
initialData:
20+
- collectionName: *collectionName
21+
databaseName: *databaseName
22+
documents:
23+
- { _id: 1, x: 11 }
24+
25+
tests:
26+
- description: "A successful command"
27+
operations:
28+
- name: runCommand
29+
object: *database
30+
arguments:
31+
command: { ping: 1 }
32+
commandName: &commandName ping
33+
expectLogMessages:
34+
- client: *client
35+
messages:
36+
- level: debug
37+
component: command
38+
data:
39+
message: "Command started"
40+
databaseName: *databaseName
41+
commandName: *commandName
42+
command:
43+
$$matchAsDocument:
44+
$$matchAsRoot:
45+
ping: 1
46+
$db: *databaseName
47+
requestId: { $$type: [int, long] }
48+
serverHost: { $$type: string }
49+
serverPort: { $$type: [int, long] }
50+
51+
- level: debug
52+
component: command
53+
data:
54+
message: "Command succeeded"
55+
commandName: *commandName
56+
reply: { $$type: string }
57+
requestId: { $$type: [int, long] }
58+
serverHost: { $$type: string }
59+
serverPort: { $$type: [int, long] }
60+
durationMS: { $$type: [double, int, long] }
61+
62+
- description: "A failed command"
63+
operations:
64+
- name: &commandName find
65+
object: *collection
66+
arguments:
67+
filter: { $or: true }
68+
expectError:
69+
isClientError: false
70+
expectLogMessages:
71+
- client: *client
72+
messages:
73+
- level: debug
74+
component: command
75+
data:
76+
message: "Command started"
77+
databaseName: *databaseName
78+
commandName: *commandName
79+
command: { $$type: string }
80+
requestId: { $$type: [int, long] }
81+
serverHost: { $$type: string }
82+
serverPort: { $$type: [int, long] }
83+
84+
- level: debug
85+
component: command
86+
data:
87+
message: "Command failed"
88+
commandName: *commandName
89+
failure: { $$exists: true }
90+
requestId: { $$type: [int, long] }
91+
serverHost: { $$type: string }
92+
serverPort: { $$type: [int, long] }
93+
durationMS: { $$type: [double, int, long] }
94+

0 commit comments

Comments
 (0)