@@ -659,41 +659,50 @@ describe('APM', function () {
659659 }
660660 } ) ;
661661
662- // NODE-1502
663- it ( 'should not allow mutation of internal state from commands returned by event monitoring' , function ( ) {
664- const started = [ ] ;
665- const succeeded = [ ] ;
666- const client = this . configuration . newClient (
667- { writeConcern : { w : 1 } } ,
668- { maxPoolSize : 1 , monitorCommands : true }
669- ) ;
670- client . on ( 'commandStarted' , filterForCommands ( 'insert' , started ) ) ;
671- client . on ( 'commandSucceeded' , filterForCommands ( 'insert' , succeeded ) ) ;
672- let documentToInsert = { a : { b : 1 } } ;
673- return client
674- . connect ( )
675- . then ( client => {
676- const db = client . db ( this . configuration . db ) ;
677- return db . collection ( 'apm_test' ) . insertOne ( documentToInsert ) ;
678- } )
679- . then ( r => {
680- expect ( r ) . to . have . property ( 'insertedId' ) . that . is . an ( 'object' ) ;
681- expect ( started ) . to . have . lengthOf ( 1 ) ;
682- // Check if contents of returned document are equal to document inserted (by value)
683- expect ( documentToInsert ) . to . deep . equal ( started [ 0 ] . command . documents [ 0 ] ) ;
684- // Check if the returned document is a clone of the original. This confirms that the
685- // reference is not the same.
686- expect ( documentToInsert !== started [ 0 ] . command . documents [ 0 ] ) . to . equal ( true ) ;
687- expect ( documentToInsert . a !== started [ 0 ] . command . documents [ 0 ] . a ) . to . equal ( true ) ;
688-
689- started [ 0 ] . command . documents [ 0 ] . a . b = 2 ;
690- expect ( documentToInsert . a . b ) . to . equal ( 1 ) ;
691-
692- expect ( started [ 0 ] . commandName ) . to . equal ( 'insert' ) ;
693- expect ( started [ 0 ] . command . insert ) . to . equal ( 'apm_test' ) ;
694- expect ( succeeded ) . to . have . lengthOf ( 1 ) ;
695- return client . close ( ) ;
696- } ) ;
662+ describe ( 'Internal state references' , function ( ) {
663+ let client ;
664+ beforeEach ( function ( ) {
665+ client = this . configuration . newClient (
666+ { writeConcern : { w : 1 } } ,
667+ { maxPoolSize : 1 , monitorCommands : true }
668+ ) ;
669+ } ) ;
670+
671+ afterEach ( function ( done ) {
672+ client . close ( done ) ;
673+ } ) ;
674+
675+ // NODE-1502
676+ it ( 'should not allow mutation of internal state from commands returned by event monitoring' , function ( ) {
677+ const started = [ ] ;
678+ const succeeded = [ ] ;
679+ client . on ( 'commandStarted' , filterForCommands ( 'insert' , started ) ) ;
680+ client . on ( 'commandSucceeded' , filterForCommands ( 'insert' , succeeded ) ) ;
681+ let documentToInsert = { a : { b : 1 } } ;
682+ return client
683+ . connect ( )
684+ . then ( client => {
685+ const db = client . db ( this . configuration . db ) ;
686+ return db . collection ( 'apm_test' ) . insertOne ( documentToInsert ) ;
687+ } )
688+ . then ( r => {
689+ expect ( r ) . to . have . property ( 'insertedId' ) . that . is . an ( 'object' ) ;
690+ expect ( started ) . to . have . lengthOf ( 1 ) ;
691+ // Check if contents of returned document are equal to document inserted (by value)
692+ expect ( documentToInsert ) . to . deep . equal ( started [ 0 ] . command . documents [ 0 ] ) ;
693+ // Check if the returned document is a clone of the original. This confirms that the
694+ // reference is not the same.
695+ expect ( documentToInsert !== started [ 0 ] . command . documents [ 0 ] ) . to . equal ( true ) ;
696+ expect ( documentToInsert . a !== started [ 0 ] . command . documents [ 0 ] . a ) . to . equal ( true ) ;
697+
698+ started [ 0 ] . command . documents [ 0 ] . a . b = 2 ;
699+ expect ( documentToInsert . a . b ) . to . equal ( 1 ) ;
700+
701+ expect ( started [ 0 ] . commandName ) . to . equal ( 'insert' ) ;
702+ expect ( started [ 0 ] . command . insert ) . to . equal ( 'apm_test' ) ;
703+ expect ( succeeded ) . to . have . lengthOf ( 1 ) ;
704+ } ) ;
705+ } ) ;
697706 } ) ;
698707
699708 describe ( 'command monitoring spec tests' , function ( ) {
0 commit comments