@@ -12,13 +12,14 @@ import {
12
12
Db ,
13
13
getTopology ,
14
14
MongoClient ,
15
+ MongoClientClosedError ,
15
16
MongoNotConnectedError ,
16
17
MongoServerSelectionError ,
17
18
ReadPreference ,
18
19
ServerDescription ,
19
20
Topology
20
21
} from '../../mongodb' ;
21
- import { runLater } from '../../tools/utils' ;
22
+ import { clearFailPoint , configureFailPoint , runLater } from '../../tools/utils' ;
22
23
import { setupDatabase } from '../shared' ;
23
24
24
25
describe ( 'class MongoClient' , function ( ) {
@@ -1064,6 +1065,51 @@ describe('class MongoClient', function () {
1064
1065
expect ( client . s . activeCursors ) . to . have . lengthOf ( 1 ) ;
1065
1066
} ) ;
1066
1067
} ) ;
1068
+
1069
+ describe ( 'maxPoolSize is not fully used when running clean up operations' , function ( ) {
1070
+ let client ;
1071
+
1072
+ beforeEach ( async function ( ) {
1073
+ await configureFailPoint ( this . configuration , {
1074
+ configureFailPoint : 'failCommand' ,
1075
+ mode : 'alwaysOn' ,
1076
+ data : {
1077
+ failCommands : [ 'insert' ] ,
1078
+ blockConnection : true ,
1079
+ blockTimeMS : 500
1080
+ }
1081
+ } ) ;
1082
+
1083
+ client = this . configuration . newClient ( { } , { maxPoolSize : 1 , monitorCommands : true } ) ;
1084
+ } ) ;
1085
+
1086
+ afterEach ( async function ( ) {
1087
+ await clearFailPoint ( this . configuration ) ;
1088
+ await client . close ( ) ;
1089
+ } ) ;
1090
+
1091
+ it (
1092
+ 'closes in-use connections before running clean up operations avoiding a deadlock' ,
1093
+ { requires : { topology : '!load-balanced' } } ,
1094
+ async ( ) => {
1095
+ const inserted = client
1096
+ . db ( 't' )
1097
+ . collection ( 't' )
1098
+ . insertOne ( { a : 1 } )
1099
+ . catch ( error => error ) ;
1100
+
1101
+ await once ( client , 'commandStarted' ) ;
1102
+
1103
+ const start = performance . now ( ) ;
1104
+ await client . close ( ) ;
1105
+ const error = await inserted ;
1106
+ const end = performance . now ( ) ;
1107
+
1108
+ expect ( end - start ) . to . be . lessThan ( 100 ) ;
1109
+ expect ( error ) . to . be . instanceOf ( MongoClientClosedError ) ;
1110
+ }
1111
+ ) ;
1112
+ } ) ;
1067
1113
} ) ;
1068
1114
1069
1115
context ( 'when connecting' , function ( ) {
0 commit comments