File tree Expand file tree Collapse file tree 6 files changed +79
-6
lines changed
test/spec/json/uri-options Expand file tree Collapse file tree 6 files changed +79
-6
lines changed Original file line number Diff line number Diff line change @@ -1178,6 +1178,12 @@ impl ClientOptions {
1178
1178
}
1179
1179
}
1180
1180
1181
+ if let Some ( 0 ) = self . max_pool_size {
1182
+ return Err ( crate :: error:: Error :: invalid_argument (
1183
+ "cannot specify maxPoolSize=0" ,
1184
+ ) ) ;
1185
+ }
1186
+
1181
1187
Ok ( ( ) )
1182
1188
}
1183
1189
Original file line number Diff line number Diff line change @@ -53,6 +53,8 @@ async fn run_test(test_file: TestFile) {
53
53
)
54
54
)
55
55
)
56
+ // The Rust driver disallows `maxPoolSize=0`.
57
+ || test_case. description . contains ( "maxPoolSize=0 does not error" )
56
58
{
57
59
continue ;
58
60
}
@@ -113,6 +115,15 @@ async fn run_test(test_file: TestFile) {
113
115
}
114
116
}
115
117
118
+ // The default types parsed from the test file don't match those serialized
119
+ // from the `ClientOptions` struct.
120
+ if let Ok ( min) = json_options. get_i32 ( "minpoolsize" ) {
121
+ json_options. insert ( "minpoolsize" , Bson :: Int64 ( min. into ( ) ) ) ;
122
+ }
123
+ if let Ok ( max) = json_options. get_i32 ( "maxpoolsize" ) {
124
+ json_options. insert ( "maxpoolsize" , Bson :: Int64 ( max. into ( ) ) ) ;
125
+ }
126
+
116
127
options_doc = options_doc
117
128
. into_iter ( )
118
129
. filter ( |( ref key, _) | json_options. contains_key ( key) )
Original file line number Diff line number Diff line change @@ -340,6 +340,10 @@ impl ConnectionPoolWorker {
340
340
} ) ;
341
341
}
342
342
343
+ fn below_max_connections ( & self ) -> bool {
344
+ self . total_connection_count < self . max_pool_size
345
+ }
346
+
343
347
fn can_service_connection_request ( & self ) -> bool {
344
348
if !matches ! ( self . state, PoolState :: Ready ) {
345
349
return false ;
@@ -349,8 +353,7 @@ impl ConnectionPoolWorker {
349
353
return true ;
350
354
}
351
355
352
- self . total_connection_count < self . max_pool_size
353
- && self . pending_connection_count < MAX_CONNECTING
356
+ self . below_max_connections ( ) && self . pending_connection_count < MAX_CONNECTING
354
357
}
355
358
356
359
async fn check_out ( & mut self , request : ConnectionRequest ) {
@@ -381,7 +384,7 @@ impl ConnectionPoolWorker {
381
384
}
382
385
383
386
// otherwise, attempt to create a connection.
384
- if self . total_connection_count < self . max_pool_size {
387
+ if self . below_max_connections ( ) {
385
388
let event_handler = self . event_handler . clone ( ) ;
386
389
let establisher = self . establisher . clone ( ) ;
387
390
let pending_connection = self . create_pending_connection ( ) ;
Original file line number Diff line number Diff line change @@ -94,6 +94,13 @@ impl Error {
94
94
. into ( )
95
95
}
96
96
97
+ pub ( crate ) fn invalid_argument ( message : impl Into < String > ) -> Error {
98
+ ErrorKind :: InvalidArgument {
99
+ message : message. into ( ) ,
100
+ }
101
+ . into ( )
102
+ }
103
+
97
104
pub ( crate ) fn is_state_change_error ( & self ) -> bool {
98
105
self . is_recovering ( ) || self . is_not_master ( )
99
106
}
Original file line number Diff line number Diff line change 2
2
"tests" : [
3
3
{
4
4
"description" : " Valid connection pool options are parsed correctly" ,
5
- "uri" : " mongodb://example.com/?maxIdleTimeMS=50000" ,
5
+ "uri" : " mongodb://example.com/?maxIdleTimeMS=50000&maxPoolSize=5&minPoolSize=3 " ,
6
6
"valid" : true ,
7
7
"warning" : false ,
8
8
"hosts" : null ,
9
9
"auth" : null ,
10
10
"options" : {
11
- "maxIdleTimeMS" : 50000
11
+ "maxIdleTimeMS" : 50000 ,
12
+ "maxPoolSize" : 5 ,
13
+ "minPoolSize" : 3
12
14
}
13
15
},
14
16
{
28
30
"hosts" : null ,
29
31
"auth" : null ,
30
32
"options" : {}
33
+ },
34
+ {
35
+ "description" : " maxPoolSize=0 does not error" ,
36
+ "uri" : " mongodb://example.com/?maxPoolSize=0" ,
37
+ "valid" : true ,
38
+ "warning" : false ,
39
+ "hosts" : null ,
40
+ "auth" : null ,
41
+ "options" : {
42
+ "maxPoolSize" : 0
43
+ }
44
+ },
45
+ {
46
+ "description" : " minPoolSize=0 does not error" ,
47
+ "uri" : " mongodb://example.com/?minPoolSize=0" ,
48
+ "valid" : true ,
49
+ "warning" : false ,
50
+ "hosts" : null ,
51
+ "auth" : null ,
52
+ "options" : {
53
+ "minPoolSize" : 0
54
+ }
31
55
}
32
56
]
33
57
}
Original file line number Diff line number Diff line change 1
1
tests :
2
2
-
3
3
description : " Valid connection pool options are parsed correctly"
4
- uri : " mongodb://example.com/?maxIdleTimeMS=50000"
4
+ uri : " mongodb://example.com/?maxIdleTimeMS=50000&maxPoolSize=5&minPoolSize=3 "
5
5
valid : true
6
6
warning : false
7
7
hosts : ~
8
8
auth : ~
9
9
options :
10
10
maxIdleTimeMS : 50000
11
+ maxPoolSize : 5
12
+ minPoolSize : 3
11
13
-
12
14
description : " Non-numeric maxIdleTimeMS causes a warning"
13
15
uri : " mongodb://example.com/?maxIdleTimeMS=invalid"
@@ -24,3 +26,23 @@ tests:
24
26
hosts : ~
25
27
auth : ~
26
28
options : {}
29
+
30
+ -
31
+ description : " maxPoolSize=0 does not error"
32
+ uri : " mongodb://example.com/?maxPoolSize=0"
33
+ valid : true
34
+ warning : false
35
+ hosts : ~
36
+ auth : ~
37
+ options :
38
+ maxPoolSize : 0
39
+
40
+ -
41
+ description : " minPoolSize=0 does not error"
42
+ uri : " mongodb://example.com/?minPoolSize=0"
43
+ valid : true
44
+ warning : false
45
+ hosts : ~
46
+ auth : ~
47
+ options :
48
+ minPoolSize : 0
You can’t perform that action at this time.
0 commit comments