@@ -15,6 +15,7 @@ const { TimeoutContext } = require('../../mongodb');
1515describe ( 'Connection Pool' , function ( ) {
1616 let timeoutContext ;
1717 let mockMongod ;
18+ let pool ;
1819 const stubServer = {
1920 topology : {
2021 client : {
@@ -50,6 +51,8 @@ describe('Connection Pool', function () {
5051 timeoutContext = TimeoutContext . create ( { waitQueueTimeoutMS : 0 , serverSelectionTimeoutMS : 0 } ) ;
5152 } ) ;
5253
54+ afterEach ( ( ) => pool ?. close ( ) ) ;
55+
5356 it ( 'should destroy connections which have been closed' , async function ( ) {
5457 mockMongod . setMessageHandler ( request => {
5558 const doc = request . document ;
@@ -61,7 +64,7 @@ describe('Connection Pool', function () {
6164 }
6265 } ) ;
6366
64- const pool = new ConnectionPool ( stubServer , {
67+ pool = new ConnectionPool ( stubServer , {
6568 maxPoolSize : 1 ,
6669 hostAddress : mockMongod . hostAddress ( )
6770 } ) ;
@@ -81,6 +84,8 @@ describe('Connection Pool', function () {
8184 expect ( events ) . to . have . length ( 1 ) ;
8285 const closeEvent = events [ 0 ] ;
8386 expect ( closeEvent ) . have . property ( 'reason' ) . equal ( 'error' ) ;
87+
88+ conn . destroy ( ) ;
8489 } ) ;
8590
8691 it ( 'should propagate socket timeouts to connections' , async function ( ) {
@@ -93,7 +98,7 @@ describe('Connection Pool', function () {
9398 }
9499 } ) ;
95100
96- const pool = new ConnectionPool ( stubServer , {
101+ pool = new ConnectionPool ( stubServer , {
97102 maxPoolSize : 1 ,
98103 socketTimeoutMS : 200 ,
99104 hostAddress : mockMongod . hostAddress ( )
@@ -117,7 +122,7 @@ describe('Connection Pool', function () {
117122 }
118123 } ) ;
119124
120- const pool = new ConnectionPool ( stubServer , {
125+ pool = new ConnectionPool ( stubServer , {
121126 maxPoolSize : 1 ,
122127 waitQueueTimeoutMS : 200 ,
123128 hostAddress : mockMongod . hostAddress ( )
@@ -157,7 +162,7 @@ describe('Connection Pool', function () {
157162 } ) ;
158163
159164 it ( 'should respect the minPoolSizeCheckFrequencyMS option' , function ( ) {
160- const pool = new ConnectionPool ( stubServer , {
165+ pool = new ConnectionPool ( stubServer , {
161166 minPoolSize : 2 ,
162167 minPoolSizeCheckFrequencyMS : 42 ,
163168 hostAddress : mockMongod . hostAddress ( )
@@ -193,7 +198,7 @@ describe('Connection Pool', function () {
193198 } ) ;
194199
195200 it ( 'should default minPoolSizeCheckFrequencyMS to 100ms' , function ( ) {
196- const pool = new ConnectionPool ( stubServer , {
201+ pool = new ConnectionPool ( stubServer , {
197202 minPoolSize : 2 ,
198203 hostAddress : mockMongod . hostAddress ( )
199204 } ) ;
0 commit comments