@@ -204,7 +204,7 @@ describe('Client Metadata Update Prose Tests', function () {
204
204
sinon . restore ( ) ;
205
205
} ) ;
206
206
207
- describe ( 'Test 1: Test that the driver updates metadata ' , function ( ) {
207
+ describe ( 'Test 2: Multiple Successive Metadata Updates ' , function ( ) {
208
208
let initialClientMetadata ;
209
209
let updatedClientMetadata ;
210
210
@@ -233,7 +233,6 @@ describe('Client Metadata Update Prose Tests', function () {
233
233
{ } ,
234
234
{
235
235
maxIdleTimeMS : 1 ,
236
- monitorCommands : true ,
237
236
driverInfo : { name : 'library' , version : '1.2' , platform : 'Library Platform' }
238
237
}
239
238
) ;
@@ -285,4 +284,80 @@ describe('Client Metadata Update Prose Tests', function () {
285
284
} ) ;
286
285
}
287
286
} ) ;
287
+
288
+ describe ( 'Test 1: Test that the driver updates metadata' , function ( ) {
289
+ let initialClientMetadata ;
290
+ let updatedClientMetadata ;
291
+
292
+ const tests = [
293
+ { testCase : 1 , name : 'framework' , version : '2.0' , platform : 'Framework Platform' } ,
294
+ { testCase : 2 , name : 'framework' , version : '2.0' } ,
295
+ { testCase : 3 , name : 'framework' , platform : 'Framework Platform' } ,
296
+ { testCase : 4 , name : 'framework' }
297
+ ] ;
298
+
299
+ for ( const { testCase, name, version, platform } of tests ) {
300
+ context ( `Case: ${ testCase } ` , function ( ) {
301
+ // 1. Create a `MongoClient` instance with the following:
302
+ // - `maxIdleTimeMS` set to `1ms`
303
+ // 2. Append the following `DriverInfoOptions` to the `MongoClient` metadata:
304
+ // | Field | Value |
305
+ // | -------- | ---------------- |
306
+ // | name | library |
307
+ // | version | 1.2 |
308
+ // | platform | Library Platform |
309
+ // 3. Send a `ping` command to the server and verify that the command succeeds.
310
+ // 4. Save intercepted `client` document as `updatedClientMetadata`.
311
+ // 5. Wait 5ms for the connection to become idle.
312
+ beforeEach ( async function ( ) {
313
+ client = this . configuration . newClient ( { } , { maxIdleTimeMS : 1 } ) ;
314
+ client . appendMetadata ( { name : 'library' , version : '1.2' , platform : 'Library Platform' } ) ;
315
+
316
+ sinon . stub ( Connection . prototype , 'command' ) . callsFake ( async function ( ns , cmd , options ) {
317
+ // @ts -expect-error: sinon will place wrappedMethod on the command method.
318
+ const command = Connection . prototype . command . wrappedMethod . bind ( this ) ;
319
+
320
+ if ( cmd . hello || cmd [ LEGACY_HELLO_COMMAND ] ) {
321
+ if ( ! initialClientMetadata ) {
322
+ initialClientMetadata = cmd . client ;
323
+ } else {
324
+ updatedClientMetadata = cmd . client ;
325
+ }
326
+ }
327
+ return command ( ns , cmd , options ) ;
328
+ } ) ;
329
+
330
+ await client . db ( 'test' ) . command ( { ping : 1 } ) ;
331
+ await sleep ( 5 ) ;
332
+ } ) ;
333
+
334
+ it ( 'appends the metadata' , async function ( ) {
335
+ // 1. Append the `DriverInfoOptions` from the selected test case to the `MongoClient` metadata.
336
+ // 2. Send a `ping` command to the server and verify:
337
+ // - The command succeeds.
338
+ // - The framework metadata is appended to the existing `DriverInfoOptions` in the `client.driver` fields of the `hello`
339
+ // command, with values separated by a pipe `|`.
340
+ client . appendMetadata ( { name, version, platform } ) ;
341
+ await client . db ( 'test' ) . command ( { ping : 1 } ) ;
342
+
343
+ expect ( updatedClientMetadata . driver . name ) . to . equal (
344
+ name
345
+ ? `${ initialClientMetadata . driver . name } |${ name } `
346
+ : initialClientMetadata . driver . name
347
+ ) ;
348
+ expect ( updatedClientMetadata . driver . version ) . to . equal (
349
+ version
350
+ ? `${ initialClientMetadata . driver . version } |${ version } `
351
+ : initialClientMetadata . driver . version
352
+ ) ;
353
+ expect ( updatedClientMetadata . platform ) . to . equal (
354
+ platform
355
+ ? `${ initialClientMetadata . platform } |${ platform } `
356
+ : initialClientMetadata . platform
357
+ ) ;
358
+ expect ( updatedClientMetadata . os ) . to . deep . equal ( initialClientMetadata . os ) ;
359
+ } ) ;
360
+ } ) ;
361
+ }
362
+ } ) ;
288
363
} ) ;
0 commit comments