@@ -22,7 +22,6 @@ use crate::{
22
22
EventClient ,
23
23
} ,
24
24
Client ,
25
- ServerInfo ,
26
25
} ;
27
26
28
27
use super :: TestTopologyDescription ;
@@ -148,6 +147,14 @@ async fn load_balancing_test() {
148
147
return ;
149
148
}
150
149
150
+ // clear the collection so subsequent test runs don't increase linearly in time
151
+ setup_client
152
+ . database ( "load_balancing_test" )
153
+ . collection :: < Document > ( "load_balancing_test" )
154
+ . drop ( )
155
+ . await
156
+ . unwrap ( ) ;
157
+
151
158
// seed the collection with a document so the find commands do some work
152
159
setup_client
153
160
. database ( "load_balancing_test" )
@@ -210,7 +217,6 @@ async fn load_balancing_test() {
210
217
211
218
let mut options = get_client_options ( ) . await . clone ( ) ;
212
219
let max_pool_size = DEFAULT_MAX_POOL_SIZE ;
213
- let hosts = options. hosts . clone ( ) ;
214
220
options. local_threshold = Duration :: from_secs ( 30 ) . into ( ) ;
215
221
options. min_pool_size = Some ( max_pool_size) ;
216
222
let client = Client :: for_test ( )
@@ -222,22 +228,7 @@ async fn load_balancing_test() {
222
228
let mut subscriber = client. events . stream_all ( ) ;
223
229
224
230
// wait for both servers pools to be saturated.
225
- for address in hosts {
226
- let selector = Arc :: new ( move |sd : & ServerInfo | sd. address ( ) == & address) ;
227
- for _ in 0 ..max_pool_size {
228
- let client = client. clone ( ) ;
229
- let selector = selector. clone ( ) ;
230
- runtime:: spawn ( async move {
231
- client
232
- . database ( "load_balancing_test" )
233
- . collection :: < Document > ( "load_balancing_test" )
234
- . find ( doc ! { "$where" : "sleep(500) && true" } )
235
- . selection_criteria ( SelectionCriteria :: Predicate ( selector) )
236
- . await
237
- . unwrap ( ) ;
238
- } ) ;
239
- }
240
- }
231
+ client. warm_connection_pool ( ) . await ;
241
232
let mut conns = 0 ;
242
233
while conns < max_pool_size * 2 {
243
234
subscriber
@@ -259,7 +250,8 @@ async fn load_balancing_test() {
259
250
let guard = setup_client. enable_fail_point ( fail_point) . await . unwrap ( ) ;
260
251
261
252
// verify that the lesser picked server (slower one) was picked less than 25% of the time.
262
- do_test ( & client, 0.05 , 0.25 , 10 ) . await ;
253
+ const FLUFF : f64 = 0.02 ; // See RUST-2044.
254
+ do_test ( & client, 0.05 , 0.25 + FLUFF , 10 ) . await ;
263
255
264
256
// disable failpoint and rerun, should be back to even split
265
257
drop ( guard) ;
0 commit comments