@@ -490,7 +490,98 @@ describe('Client Metadata Update Prose Tests', function () {
490490 }
491491 } ) ;
492492
493- describe ( 'Test 4: Metadata is not appended if identical to initial metadata' , function ( ) {
493+ describe ( 'Test 4: Multiple Metadata Updates with Duplicate Data' , function ( ) {
494+ let initialClientMetadata : ClientMetadata ;
495+ let updatedClientMetadata : ClientMetadata ;
496+ // TODO(NODE-6599): mongodb-legacy adds additional client metadata, breaking these prose tests
497+ let client : RawMongoClient ;
498+
499+ afterEach ( async function ( ) {
500+ await client . close ( ) ;
501+ } ) ;
502+
503+ it ( 'does not append duplicate metdata' , async function ( ) {
504+ // 1. Create a `MongoClient` instance with:
505+ // - `maxIdleTimeMS` set to `1ms`
506+
507+ client = new RawMongoClient ( this . configuration . url ( ) , { maxIdleTimeMS : 1 } ) ;
508+
509+ // 2. Append the following `DriverInfoOptions` to the `MongoClient` metadata:
510+ // | Field | Value |
511+ // | -------- | ---------------- |
512+ // | name | library |
513+ // | version | 1.2 |
514+ // | platform | Library Platform |
515+
516+ client . appendMetadata ( {
517+ name : 'library' ,
518+ version : '1.2' ,
519+ platform : 'Library Platform'
520+ } ) ;
521+
522+ // 3. Send a `ping` command to the server and verify that the command succeeds.
523+ await client . db ( 'test' ) . command ( { ping : 1 } ) ;
524+
525+ // 4. Wait 5ms for the connection to become idle.
526+ await sleep ( 5 ) ;
527+
528+ // 5. Append the following `DriverInfoOptions` to the `MongoClient` metadata:
529+ // | Field | Value |
530+ // | -------- | ------------------ |
531+ // | name | framework |
532+ // | version | 2.0 |
533+ // | platform | Framework Platform |
534+ client . appendMetadata ( {
535+ name : 'framework' ,
536+ version : '2.0' ,
537+ platform : 'Framework Platform'
538+ } ) ;
539+
540+ // 6. Send a `ping` command to the server and verify that the command succeeds.
541+ // 7. Save intercepted `client` document as `clientMetadata`.
542+ // 11. Save intercepted `client` document as `updatedClientMetadata`.
543+ sinon
544+ . stub ( Connection . prototype , 'command' )
545+ . callsFake ( async function ( ns , cmd , options , responseType ) {
546+ // @ts -expect-error: sinon will place wrappedMethod on the command method.
547+ const command = Connection . prototype . command . wrappedMethod . bind ( this ) ;
548+
549+ if ( cmd . hello || cmd [ LEGACY_HELLO_COMMAND ] ) {
550+ if ( ! initialClientMetadata ) {
551+ initialClientMetadata = cmd . client ;
552+ } else {
553+ updatedClientMetadata = cmd . client ;
554+ }
555+ }
556+ return command ( ns , cmd , options , responseType ) ;
557+ } ) ;
558+
559+ await client . db ( 'test' ) . command ( { ping : 1 } ) ;
560+
561+ // 8. Wait 5ms for the connection to become idle.
562+ await sleep ( 5 ) ;
563+
564+ // 9. Append the following `DriverInfoOptions` to the `MongoClient` metadata:
565+ // | Field | Value |
566+ // | -------- | ---------------- |
567+ // | name | library |
568+ // | version | 1.2 |
569+ // | platform | Library Platform |
570+ client . appendMetadata ( {
571+ name : 'library' ,
572+ version : '1.2' ,
573+ platform : 'Library Platform'
574+ } ) ;
575+
576+ // 10. Send a `ping` command to the server and verify that the command succeeds.
577+ await client . db ( 'test' ) . command ( { ping : 1 } ) ;
578+
579+ // 12. Assert that `clientMetadata` is identical to `updatedClientMetadata`.
580+ expect ( updatedClientMetadata ) . to . deep . equal ( initialClientMetadata ) ;
581+ } ) ;
582+ } ) ;
583+
584+ describe ( 'Test 5: Metadata is not appended if identical to initial metadata' , function ( ) {
494585 let initialClientMetadata : ClientMetadata ;
495586 let updatedClientMetadata : ClientMetadata ;
496587 // TODO(NODE-6599): mongodb-legacy adds additional client metadata, breaking these prose tests
@@ -567,4 +658,95 @@ describe('Client Metadata Update Prose Tests', function () {
567658 expect ( initialClientMetadata ) . to . deep . equal ( updatedClientMetadata ) ;
568659 } ) ;
569660 } ) ;
661+
662+ describe ( 'Test 6: Metadata is not appended if identical to initial metadata (separated by non-identical metadata)' , function ( ) {
663+ let initialClientMetadata : ClientMetadata ;
664+ let updatedClientMetadata : ClientMetadata ;
665+ // TODO(NODE-6599): mongodb-legacy adds additional client metadata, breaking these prose tests
666+ let client : RawMongoClient ;
667+
668+ afterEach ( async function ( ) {
669+ await client . close ( ) ;
670+ } ) ;
671+
672+ it ( 'does not append duplicate metdaata' , async function ( ) {
673+ // 1. Create a `MongoClient` instance with:
674+ // - `maxIdleTimeMS` set to `1ms`
675+ // - `driverInfo` set to the following:
676+ // | Field | Value |
677+ // | -------- | ---------------- |
678+ // | name | library |
679+ // | version | 1.2 |
680+ // | platform | Library Platform |
681+
682+ client = new RawMongoClient ( this . configuration . url ( ) , {
683+ maxIdleTimeMS : 1 ,
684+ driverInfo : {
685+ name : 'library' ,
686+ version : '1.2' ,
687+ platform : 'Library Platform'
688+ }
689+ } ) ;
690+
691+ // 2. Send a `ping` command to the server and verify that the command succeeds.
692+ await client . db ( 'test' ) . command ( { ping : 1 } ) ;
693+
694+ // 3. Wait 5ms for the connection to become idle.
695+ await sleep ( 5 ) ;
696+
697+ // 4. Append the following `DriverInfoOptions` to the `MongoClient` metadata:
698+ // | Field | Value |
699+ // | -------- | ------------------ |
700+ // | name | framework |
701+ // | version | 2.0 |
702+ // | platform | Framework Platform |
703+ client . appendMetadata ( {
704+ name : 'framework' ,
705+ version : '2.0' ,
706+ platform : 'Framework Platform'
707+ } ) ;
708+
709+ // 5. Send a `ping` command to the server and verify that the command succeeds.
710+ // 6. Save intercepted `client` document as `clientMetadata`.
711+ // 10. Save intercepted `client` document as `updatedClientMetadata`.
712+ sinon
713+ . stub ( Connection . prototype , 'command' )
714+ . callsFake ( async function ( ns , cmd , options , responseType ) {
715+ // @ts -expect-error: sinon will place wrappedMethod on the command method.
716+ const command = Connection . prototype . command . wrappedMethod . bind ( this ) ;
717+
718+ if ( cmd . hello || cmd [ LEGACY_HELLO_COMMAND ] ) {
719+ if ( ! initialClientMetadata ) {
720+ initialClientMetadata = cmd . client ;
721+ } else {
722+ updatedClientMetadata = cmd . client ;
723+ }
724+ }
725+ return command ( ns , cmd , options , responseType ) ;
726+ } ) ;
727+
728+ await client . db ( 'test' ) . command ( { ping : 1 } ) ;
729+
730+ // 7. Wait 5ms for the connection to become idle.
731+ await sleep ( 5 ) ;
732+
733+ // 8. Append the following `DriverInfoOptions` to the `MongoClient` metadata:
734+ // | Field | Value |
735+ // | -------- | ---------------- |
736+ // | name | library |
737+ // | version | 1.2 |
738+ // | platform | Library Platform |
739+ client . appendMetadata ( {
740+ name : 'library' ,
741+ version : '1.2' ,
742+ platform : 'Library Platform'
743+ } ) ;
744+
745+ // 9. Send a `ping` command to the server and verify that the command succeeds.
746+ await client . db ( 'test' ) . command ( { ping : 1 } ) ;
747+
748+ // 11. Assert that `clientMetadata` is identical to `updatedClientMetadata`.
749+ expect ( updatedClientMetadata ) . to . deep . equal ( initialClientMetadata ) ;
750+ } ) ;
751+ } ) ;
570752} ) ;
0 commit comments