Skip to content

Commit b54837f

Browse files
authored
RUST-2044 Improve server selection prose test (#1208)
1 parent 8907508 commit b54837f

File tree

1 file changed

+11
-19
lines changed
  • src/sdam/description/topology/server_selection/test

1 file changed

+11
-19
lines changed

src/sdam/description/topology/server_selection/test/in_window.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use crate::{
2222
EventClient,
2323
},
2424
Client,
25-
ServerInfo,
2625
};
2726

2827
use super::TestTopologyDescription;
@@ -148,6 +147,14 @@ async fn load_balancing_test() {
148147
return;
149148
}
150149

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+
151158
// seed the collection with a document so the find commands do some work
152159
setup_client
153160
.database("load_balancing_test")
@@ -210,7 +217,6 @@ async fn load_balancing_test() {
210217

211218
let mut options = get_client_options().await.clone();
212219
let max_pool_size = DEFAULT_MAX_POOL_SIZE;
213-
let hosts = options.hosts.clone();
214220
options.local_threshold = Duration::from_secs(30).into();
215221
options.min_pool_size = Some(max_pool_size);
216222
let client = Client::for_test()
@@ -222,22 +228,7 @@ async fn load_balancing_test() {
222228
let mut subscriber = client.events.stream_all();
223229

224230
// 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;
241232
let mut conns = 0;
242233
while conns < max_pool_size * 2 {
243234
subscriber
@@ -259,7 +250,8 @@ async fn load_balancing_test() {
259250
let guard = setup_client.enable_fail_point(fail_point).await.unwrap();
260251

261252
// 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;
263255

264256
// disable failpoint and rerun, should be back to even split
265257
drop(guard);

0 commit comments

Comments
 (0)