@@ -99,11 +99,41 @@ describe.skip('MongoClient.close() Integration', () => {
9999
100100 describe ( 'Connection Monitoring' , ( ) => {
101101 describe ( 'Node.js resource: Socket' , ( ) => {
102- it ( 'no sockets remain after client.close()' , metadata , async function ( ) { } ) ;
102+ it ( 'no sockets remain after client.close()' , metadata , async function ( ) {
103+ await runScriptAndGetProcessInfo (
104+ 'socket-connection-monitoring' ,
105+ config ,
106+ async function run ( { MongoClient, uri, log, chai } ) {
107+ const client = new MongoClient ( uri , { serverMonitoringMode : 'auto' } ) ;
108+ await client . connect ( ) ;
109+
110+ // returns all active tcp endpoints
111+ const connectionMonitoringReport = ( ) => process . report . getReport ( ) . libuv . filter ( r => r . type === 'tcp' && r . is_active ) . map ( r => r . remoteEndpoint ) ;
112+
113+ log ( { report : connectionMonitoringReport ( ) } ) ;
114+ // assert socket creation
115+ const servers = client . topology ?. s . servers ;
116+ for ( const server of servers ) {
117+ let { host, port } = server [ 1 ] . s . description . hostAddress ;
118+ chai . expect ( connectionMonitoringReport ( ) ) . to . deep . include ( { host, port } ) ;
119+ }
120+
121+ await client . close ( ) ;
122+
123+ // assert socket destruction
124+ for ( const server of servers ) {
125+ let { host, port } = server [ 1 ] . s . description . hostAddress ;
126+ chai . expect ( connectionMonitoringReport ( ) ) . to . not . deep . include ( { host, port } ) ;
127+ }
128+ }
129+ ) ;
130+ } ) ;
103131 } ) ;
104132
105133 describe ( 'Server resource: connection thread' , ( ) => {
106- it ( 'no connection threads remain after client.close()' , metadata , async ( ) => { } ) ;
134+ it ( 'no connection threads remain after client.close()' , metadata , async ( ) => {
135+
136+ } ) ;
107137 } ) ;
108138 } ) ;
109139
@@ -112,14 +142,48 @@ describe.skip('MongoClient.close() Integration', () => {
112142 describe ( 'after entering monitor streaming mode ' , ( ) => {
113143 it ( 'the rtt pinger timer is cleaned up by client.close()' , async ( ) => {
114144 // helloReply has a topologyVersion defined
115- } ) ;
145+ await runScriptAndGetProcessInfo (
146+ 'socket-connection-monitoring' ,
147+ config ,
148+ async function run ( { MongoClient, uri, expect } ) {
149+ const client = new MongoClient ( uri , { serverMonitoringMode : 'stream' , minHeartbeatFrequencyMS : 10000 } ) ;
150+ await client . connect ( ) ;
151+ } ) ;
116152 } ) ;
117153 } ) ;
118154
119155 describe ( 'Connection' , ( ) => {
120156 describe ( 'Node.js resource: Socket' , ( ) => {
121157 describe ( 'when rtt monitoring is turned on' , ( ) => {
122- it ( 'no sockets remain after client.close()' , async ( ) => { } ) ;
158+ it ( 'no sockets remain after client.close()' , async ( ) => {
159+ await runScriptAndGetProcessInfo (
160+ 'socket-connection-monitoring' ,
161+ config ,
162+ async function run ( { MongoClient, uri, log, expect } ) {
163+ const client = new MongoClient ( uri , { serverMonitoringMode : 'stream' , minHeartbeatFrequencyMS : 10000 } ) ;
164+ await client . connect ( ) ;
165+
166+ // returns all active tcp endpoints
167+ const connectionMonitoringReport = ( ) => process . report . getReport ( ) . libuv . filter ( r => r . type === 'tcp' && r . is_active ) . map ( r => r . remoteEndpoint ) ;
168+
169+ log ( { report : connectionMonitoringReport ( ) } ) ;
170+ // assert socket creation
171+ const servers = client . topology ?. s . servers ;
172+ for ( const server of servers ) {
173+ let { host, port } = server [ 1 ] . s . description . hostAddress ;
174+ chai . expect ( connectionMonitoringReport ( ) ) . to . deep . include ( { host, port } ) ;
175+ }
176+
177+ await client . close ( ) ;
178+
179+ // assert socket destruction
180+ for ( const server of servers ) {
181+ let { host, port } = server [ 1 ] . s . description . hostAddress ;
182+ chai . expect ( connectionMonitoringReport ( ) ) . to . not . deep . include ( { host, port } ) ;
183+ }
184+ }
185+ ) ;
186+ } ) ;
123187 } ) ;
124188 } ) ;
125189
0 commit comments