@@ -2,30 +2,30 @@ import { expect } from 'chai';
2
2
3
3
import { DEFAULT_MAX_DOCUMENT_LENGTH , type Document } from '../../mongodb' ;
4
4
5
- describe . only ( 'Command Logging and Monitoring Prose Tests' , function ( ) {
5
+ describe ( 'Command Logging and Monitoring Prose Tests' , function ( ) {
6
6
const loggerFeatureFlag = Symbol . for ( '@@mdb.enableMongoLogger' ) ;
7
7
const ELLIPSES_LENGTH = 3 ;
8
8
let client ;
9
9
let writable ;
10
10
11
11
context ( 'When no custom truncation limit is provided' , function ( ) {
12
12
/*
13
- 1. Configure logging with a minimum severity level of "debug" for the "command" component.
13
+ 1. Configure logging with a minimum severity level of "debug" for the "command" component.
14
14
Do not explicitly configure the max document length.
15
15
16
16
2. Construct an array docs containing the document {"x" : "y"} repeated 100 times.
17
17
18
18
3. Insert docs to a collection via insertMany.
19
19
20
- 4. Inspect the resulting "command started" log message and assert that
20
+ 4. Inspect the resulting "command started" log message and assert that
21
21
the "command" value is a string of length 1000 + (length of trailing ellipsis).
22
22
23
- 5. Inspect the resulting "command succeeded" log message and assert that
23
+ 5. Inspect the resulting "command succeeded" log message and assert that
24
24
the "reply" value is a string of length <= 1000 + (length of trailing ellipsis).
25
25
26
26
6. Run find() on the collection where the document was inserted.
27
27
28
- 7. Inspect the resulting "command succeeded" log message and assert that
28
+ 7. Inspect the resulting "command succeeded" log message and assert that
29
29
the reply is a string of length 1000 + (length of trailing ellipsis).
30
30
*/
31
31
@@ -53,67 +53,64 @@ describe.only('Command Logging and Monitoring Prose Tests', function () {
53
53
await client . close ( ) ;
54
54
} ) ;
55
55
56
- it ( 'should follow default truncation limit of 1000' , {
57
- metadata : { } ,
58
- test : async function ( ) {
59
- // 2.
60
- const docs : Array < Document > = [ ] ;
61
- for ( let i = 0 ; i < 100 ; i ++ ) {
62
- docs . push ( { x : 'y' } ) ;
63
- }
64
-
65
- // 3.
66
- await client . db ( 'admin' ) . collection ( 'test' ) . insertMany ( docs ) ;
67
-
68
- // 4.
69
- const insertManyCommandStarted = writable . buffer [ 0 ] ;
70
- expect ( insertManyCommandStarted ?. message ) . to . equal ( 'Command started' ) ;
71
- expect ( insertManyCommandStarted ?. command ) . to . be . a ( 'string' ) ;
72
- expect ( insertManyCommandStarted ?. command ?. length ) . to . equal (
73
- DEFAULT_MAX_DOCUMENT_LENGTH + ELLIPSES_LENGTH
74
- ) ;
75
-
76
- // 5.
77
- const insertManyCommandSucceeded = writable . buffer [ 1 ] ;
78
- expect ( insertManyCommandSucceeded ?. message ) . to . equal ( 'Command succeeded' ) ;
79
- expect ( insertManyCommandSucceeded ?. reply ) . to . be . a ( 'string' ) ;
80
- expect ( insertManyCommandSucceeded ?. reply ?. length ) . to . be . at . most (
81
- DEFAULT_MAX_DOCUMENT_LENGTH + ELLIPSES_LENGTH
82
- ) ;
83
-
84
- // 6.
85
- await client . db ( 'admin' ) . collection ( 'test' ) . find ( ) . toArray ( ) ;
86
-
87
- // 7.
88
- const findCommandSucceeded = writable . buffer [ 3 ] ;
89
- expect ( findCommandSucceeded ?. message ) . to . equal ( 'Command succeeded' ) ;
90
- expect ( findCommandSucceeded ?. reply ) . to . be . a ( 'string' ) ;
91
- expect ( findCommandSucceeded ?. reply ?. length ) . to . equal (
92
- DEFAULT_MAX_DOCUMENT_LENGTH + ELLIPSES_LENGTH
93
- ) ;
56
+ it ( 'should follow default truncation limit of 1000' , async function ( ) {
57
+ // 2.
58
+ const docs : Array < Document > = [ ] ;
59
+ for ( let i = 0 ; i < 100 ; i ++ ) {
60
+ docs . push ( { x : 'y' } ) ;
94
61
}
62
+
63
+ // 3.
64
+ await client . db ( 'admin' ) . collection ( 'test' ) . insertMany ( docs ) ;
65
+
66
+ // 4.
67
+ const insertManyCommandStarted = writable . buffer [ 0 ] ;
68
+ expect ( insertManyCommandStarted ?. message ) . to . equal ( 'Command started' ) ;
69
+ expect ( insertManyCommandStarted ?. command ) . to . be . a ( 'string' ) ;
70
+ expect ( insertManyCommandStarted ?. command ?. length ) . to . equal (
71
+ DEFAULT_MAX_DOCUMENT_LENGTH + ELLIPSES_LENGTH
72
+ ) ;
73
+
74
+ // 5.
75
+ const insertManyCommandSucceeded = writable . buffer [ 1 ] ;
76
+ expect ( insertManyCommandSucceeded ?. message ) . to . equal ( 'Command succeeded' ) ;
77
+ expect ( insertManyCommandSucceeded ?. reply ) . to . be . a ( 'string' ) ;
78
+ expect ( insertManyCommandSucceeded ?. reply ?. length ) . to . be . at . most (
79
+ DEFAULT_MAX_DOCUMENT_LENGTH + ELLIPSES_LENGTH
80
+ ) ;
81
+
82
+ // 6.
83
+ await client . db ( 'admin' ) . collection ( 'test' ) . find ( ) . toArray ( ) ;
84
+
85
+ // 7.
86
+ const findCommandSucceeded = writable . buffer [ 3 ] ;
87
+ expect ( findCommandSucceeded ?. message ) . to . equal ( 'Command succeeded' ) ;
88
+ expect ( findCommandSucceeded ?. reply ) . to . be . a ( 'string' ) ;
89
+ expect ( findCommandSucceeded ?. reply ?. length ) . to . equal (
90
+ DEFAULT_MAX_DOCUMENT_LENGTH + ELLIPSES_LENGTH
91
+ ) ;
95
92
} ) ;
96
93
} ) ;
97
94
98
95
context ( 'When custom truncation limit is provided' , function ( ) {
99
96
/*
100
- 1. Configure logging with a minimum severity level of "debug" for the "command" component.
97
+ 1. Configure logging with a minimum severity level of "debug" for the "command" component.
101
98
Set the max document length to 5.
102
99
103
100
2. Run the command {"hello": true}.
104
101
105
- 3. Inspect the resulting "command started" log message and assert that
102
+ 3. Inspect the resulting "command started" log message and assert that
106
103
the "command" value is a string of length 5 + (length of trailing ellipsis).
107
104
108
105
4. Inspect the resulting "command succeeded" log message and assert that
109
106
the "reply" value is a string of length 5 + (length of trailing ellipsis).
110
-
107
+
111
108
5. (Optional)
112
109
If the driver attaches raw server responses to failures
113
- and can access these via log messages to assert on,
114
- run the command {"notARealCommand": true}.
110
+ and can access these via log messages to assert on,
111
+ run the command {"notARealCommand": true}.
115
112
116
- Inspect the resulting "command failed" log message
113
+ Inspect the resulting "command failed" log message
117
114
and confirm that the server error is a string of length 5 + (length of trailing ellipsis).
118
115
*/
119
116
beforeEach ( async function ( ) {
@@ -141,38 +138,33 @@ describe.only('Command Logging and Monitoring Prose Tests', function () {
141
138
await client . close ( ) ;
142
139
} ) ;
143
140
144
- it ( 'should follow custom truncation limit' , {
145
- metadata : { } ,
146
- test : async function ( ) {
147
- // 2.
148
- await client . db ( 'admin' ) . command ( { hello : 'true' } ) ;
149
-
150
- // 3.
151
- const insertManyCommandStarted = writable . buffer [ 0 ] ;
152
- expect ( insertManyCommandStarted ?. message ) . to . equal ( 'Command started' ) ;
153
- expect ( insertManyCommandStarted ?. command ) . to . be . a ( 'string' ) ;
154
- expect ( insertManyCommandStarted ?. command ?. length ) . to . equal ( 5 + ELLIPSES_LENGTH ) ;
155
-
156
- // 4.
157
- const insertManyCommandSucceeded = writable . buffer [ 1 ] ;
158
- expect ( insertManyCommandSucceeded ?. message ) . to . equal ( 'Command succeeded' ) ;
159
- expect ( insertManyCommandSucceeded ?. reply ) . to . be . a ( 'string' ) ;
160
- expect ( insertManyCommandSucceeded ?. reply ?. length ) . to . be . at . most ( 5 + ELLIPSES_LENGTH ) ;
161
-
162
- await client . close ( ) ;
163
- }
141
+ it ( 'should follow custom truncation limit' , async function ( ) {
142
+ // 2.
143
+ await client . db ( 'admin' ) . command ( { hello : 'true' } ) ;
144
+
145
+ // 3.
146
+ const insertManyCommandStarted = writable . buffer [ 0 ] ;
147
+ expect ( insertManyCommandStarted ?. message ) . to . equal ( 'Command started' ) ;
148
+ expect ( insertManyCommandStarted ?. command ) . to . be . a ( 'string' ) ;
149
+ expect ( insertManyCommandStarted ?. command ?. length ) . to . equal ( 5 + ELLIPSES_LENGTH ) ;
150
+
151
+ // 4.
152
+ const insertManyCommandSucceeded = writable . buffer [ 1 ] ;
153
+ expect ( insertManyCommandSucceeded ?. message ) . to . equal ( 'Command succeeded' ) ;
154
+ expect ( insertManyCommandSucceeded ?. reply ) . to . be . a ( 'string' ) ;
155
+ expect ( insertManyCommandSucceeded ?. reply ?. length ) . to . be . at . most ( 5 + ELLIPSES_LENGTH ) ;
164
156
} ) ;
165
157
} ) ;
166
158
167
159
context ( 'Truncation with multi-byte codepoints' , function ( ) {
168
160
/*
169
161
A specific test case is not provided here due to the allowed variations in truncation logic
170
- as well as varying extended JSON whitespace usage.
171
- Drivers MUST write language-specific tests that confirm truncation of commands, replies,
172
- and (if applicable) server responses included in error messages
162
+ as well as varying extended JSON whitespace usage.
163
+ Drivers MUST write language-specific tests that confirm truncation of commands, replies,
164
+ and (if applicable) server responses included in error messages
173
165
work as expected when the data being truncated includes multi-byte Unicode codepoints.
174
-
175
- If the driver uses anything other than Unicode codepoints as the unit for max document length,
166
+
167
+ If the driver uses anything other than Unicode codepoints as the unit for max document length,
176
168
there also MUST be tests confirming that cases
177
169
where the max length falls in the middle of a multi-byte codepoint are handled gracefully.
178
170
*/
@@ -202,27 +194,24 @@ describe.only('Command Logging and Monitoring Prose Tests', function () {
202
194
await client . close ( ) ;
203
195
} ) ;
204
196
205
- it ( 'should handle unicode codepoints in middle and end of truncation gracefully' , {
206
- metadata : { } ,
207
- test : async function ( ) {
208
- const docs : Array < Document > = [
209
- {
210
- x : '\u2603\u2603\u2603\u2603'
211
- }
212
- ] ;
197
+ it ( 'should handle unicode codepoints in middle and end of truncation gracefully' , async function ( ) {
198
+ const docs : Array < Document > = [
199
+ {
200
+ x : '\u2603\u2603\u2603\u2603'
201
+ }
202
+ ] ;
213
203
214
- await client . db ( 'admin' ) . collection ( 'test' ) . insertMany ( docs ) ;
204
+ await client . db ( 'admin' ) . collection ( 'test' ) . insertMany ( docs ) ;
215
205
216
- const insertManyCommandStarted = writable . buffer [ 0 ] ;
217
- expect ( insertManyCommandStarted ?. message ) . to . equal ( 'Command started' ) ;
218
- expect ( insertManyCommandStarted ?. command ) . to . be . a ( 'string' ) ;
219
- expect ( insertManyCommandStarted ?. command ?. length ) . to . equal ( 50 + ELLIPSES_LENGTH ) ;
206
+ const insertManyCommandStarted = writable . buffer [ 0 ] ;
207
+ expect ( insertManyCommandStarted ?. message ) . to . equal ( 'Command started' ) ;
208
+ expect ( insertManyCommandStarted ?. command ) . to . be . a ( 'string' ) ;
209
+ expect ( insertManyCommandStarted ?. command ?. length ) . to . equal ( 50 + ELLIPSES_LENGTH ) ;
220
210
221
- const insertManyCommandSucceeded = writable . buffer [ 1 ] ;
222
- expect ( insertManyCommandSucceeded ?. message ) . to . equal ( 'Command succeeded' ) ;
223
- expect ( insertManyCommandSucceeded ?. reply ) . to . be . a ( 'string' ) ;
224
- expect ( insertManyCommandSucceeded ?. reply ?. length ) . to . be . at . most ( 50 + ELLIPSES_LENGTH ) ;
225
- }
211
+ const insertManyCommandSucceeded = writable . buffer [ 1 ] ;
212
+ expect ( insertManyCommandSucceeded ?. message ) . to . equal ( 'Command succeeded' ) ;
213
+ expect ( insertManyCommandSucceeded ?. reply ) . to . be . a ( 'string' ) ;
214
+ expect ( insertManyCommandSucceeded ?. reply ?. length ) . to . be . at . most ( 50 + ELLIPSES_LENGTH ) ;
226
215
} ) ;
227
216
} ) ;
228
217
} ) ;
0 commit comments