Skip to content

Commit 405eca5

Browse files
authored
RUST-1449 Simplify test client creation (#1189)
1 parent dd3e69f commit 405eca5

36 files changed

+388
-434
lines changed

src/client/session/test.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use crate::{
1919
util::event_buffer::EventBuffer,
2020
Event,
2121
EventClient,
22-
TestClient,
2322
},
2423
Client,
2524
Collection,
@@ -196,7 +195,7 @@ macro_rules! for_each_op {
196195
/// This test also satisifies the `endSession` testing requirement of prose test 5.
197196
#[tokio::test]
198197
async fn pool_is_lifo() {
199-
let client = TestClient::new().await;
198+
let client = Client::for_test().await;
200199
// Wait for the implicit sessions created in TestClient::new to be returned to the pool.
201200
tokio::time::sleep(Duration::from_millis(500)).await;
202201

@@ -229,7 +228,7 @@ async fn pool_is_lifo() {
229228
#[tokio::test]
230229
#[function_name::named]
231230
async fn cluster_time_in_commands() {
232-
let test_client = TestClient::new().await;
231+
let test_client = Client::for_test().await;
233232
if test_client.is_standalone() {
234233
log_uncaptured("skipping cluster_time_in_commands test due to standalone topology");
235234
return;
@@ -375,7 +374,7 @@ async fn cluster_time_in_commands() {
375374
#[tokio::test]
376375
#[function_name::named]
377376
async fn session_usage() {
378-
let client = TestClient::new().await;
377+
let client = Client::for_test().await;
379378
if client.is_standalone() {
380379
return;
381380
}
@@ -385,7 +384,7 @@ async fn session_usage() {
385384
F: Fn(EventClient) -> G,
386385
G: Future<Output = ()>,
387386
{
388-
let client = Client::test_builder().monitor_events().build().await;
387+
let client = Client::for_test().monitor_events().await;
389388
operation(client.clone()).await;
390389
let (command_started, _) = client.events.get_successful_command_execution(command_name);
391390
assert!(
@@ -402,7 +401,7 @@ async fn session_usage() {
402401
#[tokio::test]
403402
#[function_name::named]
404403
async fn implicit_session_returned_after_immediate_exhaust() {
405-
let client = Client::test_builder().monitor_events().build().await;
404+
let client = Client::for_test().monitor_events().await;
406405
if client.is_standalone() {
407406
return;
408407
}
@@ -442,7 +441,7 @@ async fn implicit_session_returned_after_immediate_exhaust() {
442441
#[tokio::test]
443442
#[function_name::named]
444443
async fn implicit_session_returned_after_exhaust_by_get_more() {
445-
let client = Client::test_builder().monitor_events().build().await;
444+
let client = Client::for_test().monitor_events().await;
446445
if client.is_standalone() {
447446
return;
448447
}
@@ -492,7 +491,7 @@ async fn implicit_session_returned_after_exhaust_by_get_more() {
492491
#[tokio::test]
493492
#[function_name::named]
494493
async fn find_and_getmore_share_session() {
495-
let client = Client::test_builder().monitor_events().build().await;
494+
let client = Client::for_test().monitor_events().await;
496495
if client.is_standalone() {
497496
log_uncaptured(
498497
"skipping find_and_getmore_share_session due to unsupported topology: Standalone",

src/client/session/test/causal_consistency.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn all_session_ops() -> impl Iterator<Item = Operation> {
118118
/// Test 1 from the causal consistency specification.
119119
#[tokio::test]
120120
async fn new_session_operation_time_null() {
121-
let client = Client::test_builder().monitor_events().build().await;
121+
let client = Client::for_test().monitor_events().await;
122122

123123
if client.is_standalone() {
124124
log_uncaptured(
@@ -134,7 +134,7 @@ async fn new_session_operation_time_null() {
134134
/// Test 2 from the causal consistency specification.
135135
#[tokio::test]
136136
async fn first_read_no_after_cluser_time() {
137-
let client = Client::test_builder().monitor_events().build().await;
137+
let client = Client::for_test().monitor_events().await;
138138

139139
if client.is_standalone() {
140140
log_uncaptured(
@@ -172,7 +172,7 @@ async fn first_read_no_after_cluser_time() {
172172
/// Test 3 from the causal consistency specification.
173173
#[tokio::test]
174174
async fn first_op_update_op_time() {
175-
let client = Client::test_builder().monitor_events().build().await;
175+
let client = Client::for_test().monitor_events().await;
176176

177177
if client.is_standalone() {
178178
log_uncaptured("skipping first_op_update_op_time due to unsupported topology: standalone");
@@ -221,7 +221,7 @@ async fn first_op_update_op_time() {
221221
/// Test 4 from the causal consistency specification.
222222
#[tokio::test]
223223
async fn read_includes_after_cluster_time() {
224-
let client = Client::test_builder().monitor_events().build().await;
224+
let client = Client::for_test().monitor_events().await;
225225

226226
if client.is_standalone() {
227227
log_uncaptured(
@@ -262,7 +262,7 @@ async fn read_includes_after_cluster_time() {
262262
/// Test 5 from the causal consistency specification.
263263
#[tokio::test]
264264
async fn find_after_write_includes_after_cluster_time() {
265-
let client = Client::test_builder().monitor_events().build().await;
265+
let client = Client::for_test().monitor_events().await;
266266

267267
if client.is_standalone() {
268268
log_uncaptured(
@@ -306,7 +306,7 @@ async fn find_after_write_includes_after_cluster_time() {
306306
/// Test 6 from the causal consistency specification.
307307
#[tokio::test]
308308
async fn not_causally_consistent_omits_after_cluster_time() {
309-
let client = Client::test_builder().monitor_events().build().await;
309+
let client = Client::for_test().monitor_events().await;
310310

311311
if client.is_standalone() {
312312
log_uncaptured(
@@ -345,7 +345,7 @@ async fn not_causally_consistent_omits_after_cluster_time() {
345345
/// Test 7 from the causal consistency specification.
346346
#[tokio::test]
347347
async fn omit_after_cluster_time_standalone() {
348-
let client = Client::test_builder().monitor_events().build().await;
348+
let client = Client::for_test().monitor_events().await;
349349

350350
if !client.is_standalone() {
351351
log_uncaptured("skipping omit_after_cluster_time_standalone due to unsupported topology");
@@ -381,7 +381,7 @@ async fn omit_after_cluster_time_standalone() {
381381
/// Test 8 from the causal consistency specification.
382382
#[tokio::test]
383383
async fn omit_default_read_concern_level() {
384-
let client = Client::test_builder().monitor_events().build().await;
384+
let client = Client::for_test().monitor_events().await;
385385

386386
if client.is_standalone() {
387387
log_uncaptured(
@@ -421,7 +421,7 @@ async fn omit_default_read_concern_level() {
421421
/// Test 9 from the causal consistency specification.
422422
#[tokio::test]
423423
async fn test_causal_consistency_read_concern_merge() {
424-
let client = Client::test_builder().monitor_events().build().await;
424+
let client = Client::for_test().monitor_events().await;
425425
if client.is_standalone() {
426426
log_uncaptured(
427427
"skipping test_causal_consistency_read_concern_merge due to unsupported topology: \
@@ -470,7 +470,7 @@ async fn test_causal_consistency_read_concern_merge() {
470470
/// Test 11 from the causal consistency specification.
471471
#[tokio::test]
472472
async fn omit_cluster_time_standalone() {
473-
let client = Client::test_builder().monitor_events().build().await;
473+
let client = Client::for_test().monitor_events().await;
474474
if !client.is_standalone() {
475475
log_uncaptured("skipping omit_cluster_time_standalone due to unsupported topology");
476476
return;
@@ -489,7 +489,7 @@ async fn omit_cluster_time_standalone() {
489489
/// Test 12 from the causal consistency specification.
490490
#[tokio::test]
491491
async fn cluster_time_sent_in_commands() {
492-
let client = Client::test_builder().monitor_events().build().await;
492+
let client = Client::for_test().monitor_events().await;
493493
if client.is_standalone() {
494494
log_uncaptured("skipping cluster_time_sent_in_commands due to unsupported topology");
495495
return;

src/cmap/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ async fn cmap_spec_tests() {
441441
}
442442
options.hosts.drain(1..);
443443
options.direct_connection = Some(true);
444-
let client = crate::Client::test_builder().options(options).build().await;
444+
let client = crate::Client::for_test().options(options).await;
445445
if let Some(ref run_on) = test_file.run_on {
446446
let can_run_on = run_on.iter().any(|run_on| run_on.can_run_on(&client));
447447
if !can_run_on {

src/cmap/test/integration.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ use crate::{
2323
event_buffer::EventBuffer,
2424
fail_point::{FailPoint, FailPointMode},
2525
},
26-
TestClient,
2726
},
27+
Client,
2828
};
2929
use semver::VersionReq;
3030
use std::time::Duration;
@@ -92,7 +92,7 @@ async fn concurrent_connections() {
9292
options.direct_connection = Some(true);
9393
options.hosts.drain(1..);
9494

95-
let client = TestClient::with_options(Some(options)).await;
95+
let client = Client::for_test().options(options).await;
9696
let version = VersionReq::parse(">= 4.2.9").unwrap();
9797
// blockConnection failpoint option only supported in 4.2.9+.
9898
if !version.matches(&client.server_version) {
@@ -181,7 +181,7 @@ async fn connection_error_during_establishment() {
181181
client_options.direct_connection = Some(true);
182182
client_options.repl_set_name = None;
183183

184-
let client = TestClient::with_options(Some(client_options.clone())).await;
184+
let client = Client::for_test().options(client_options.clone()).await;
185185
if !client.supports_fail_command() {
186186
log_uncaptured(format!(
187187
"skipping {} due to failCommand not being supported",
@@ -236,7 +236,7 @@ async fn connection_error_during_operation() {
236236
options.hosts.drain(1..);
237237
options.max_pool_size = Some(1);
238238

239-
let client = TestClient::with_options(options).await;
239+
let client = Client::for_test().options(options).await;
240240
if !client.supports_fail_command() {
241241
log_uncaptured(format!(
242242
"skipping {} due to failCommand not being supported",

src/concern/test.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
bson::{doc, Bson, Document},
55
error::ErrorKind,
66
options::{Acknowledgment, ReadConcern, WriteConcern},
7-
test::{EventClient, TestClient},
7+
test::EventClient,
88
Client,
99
Collection,
1010
};
@@ -92,7 +92,7 @@ fn write_concern_deserialize() {
9292
#[tokio::test]
9393
#[function_name::named]
9494
async fn inconsistent_write_concern_rejected() {
95-
let client = TestClient::new().await;
95+
let client = Client::for_test().await;
9696
let db = client.database(function_name!());
9797

9898
let coll = db.collection(function_name!());
@@ -112,7 +112,7 @@ async fn inconsistent_write_concern_rejected() {
112112
#[tokio::test]
113113
#[function_name::named]
114114
async fn unacknowledged_write_concern_rejected() {
115-
let client = TestClient::new().await;
115+
let client = Client::for_test().await;
116116
let db = client.database(function_name!());
117117
let coll = db.collection(function_name!());
118118
let wc = WriteConcern {
@@ -131,7 +131,7 @@ async fn unacknowledged_write_concern_rejected() {
131131
#[tokio::test]
132132
#[function_name::named]
133133
async fn snapshot_read_concern() {
134-
let client = Client::test_builder().monitor_events().build().await;
134+
let client = Client::for_test().monitor_events().await;
135135
// snapshot read concern was introduced in 4.0
136136
if client.server_version_lt(4, 0) {
137137
return;
@@ -186,7 +186,7 @@ async fn assert_event_contains_read_concern(client: &EventClient) {
186186
#[tokio::test]
187187
#[function_name::named]
188188
async fn command_contains_write_concern_insert_one() {
189-
let client = Client::test_builder().monitor_events().build().await;
189+
let client = Client::for_test().monitor_events().await;
190190
let coll: Collection<Document> = client.database("test").collection(function_name!());
191191

192192
coll.drop().await.unwrap();
@@ -227,7 +227,7 @@ async fn command_contains_write_concern_insert_one() {
227227
#[tokio::test]
228228
#[function_name::named]
229229
async fn command_contains_write_concern_insert_many() {
230-
let client = Client::test_builder().monitor_events().build().await;
230+
let client = Client::for_test().monitor_events().await;
231231
let coll: Collection<Document> = client.database("test").collection(function_name!());
232232

233233
coll.drop().await.unwrap();
@@ -268,7 +268,7 @@ async fn command_contains_write_concern_insert_many() {
268268
#[tokio::test]
269269
#[function_name::named]
270270
async fn command_contains_write_concern_update_one() {
271-
let client = Client::test_builder().monitor_events().build().await;
271+
let client = Client::for_test().monitor_events().await;
272272
let coll: Collection<Document> = client.database("test").collection(function_name!());
273273

274274
coll.drop().await.unwrap();
@@ -310,7 +310,7 @@ async fn command_contains_write_concern_update_one() {
310310
#[tokio::test]
311311
#[function_name::named]
312312
async fn command_contains_write_concern_update_many() {
313-
let client = Client::test_builder().monitor_events().build().await;
313+
let client = Client::for_test().monitor_events().await;
314314
let coll: Collection<Document> = client.database("test").collection(function_name!());
315315

316316
coll.drop().await.unwrap();
@@ -354,7 +354,7 @@ async fn command_contains_write_concern_update_many() {
354354
#[tokio::test]
355355
#[function_name::named]
356356
async fn command_contains_write_concern_replace_one() {
357-
let client = Client::test_builder().monitor_events().build().await;
357+
let client = Client::for_test().monitor_events().await;
358358
let coll: Collection<Document> = client.database("test").collection(function_name!());
359359

360360
coll.drop().await.unwrap();
@@ -396,7 +396,7 @@ async fn command_contains_write_concern_replace_one() {
396396
#[tokio::test]
397397
#[function_name::named]
398398
async fn command_contains_write_concern_delete_one() {
399-
let client = Client::test_builder().monitor_events().build().await;
399+
let client = Client::for_test().monitor_events().await;
400400
let coll: Collection<Document> = client.database("test").collection(function_name!());
401401

402402
coll.drop().await.unwrap();
@@ -440,7 +440,7 @@ async fn command_contains_write_concern_delete_one() {
440440
#[tokio::test]
441441
#[function_name::named]
442442
async fn command_contains_write_concern_delete_many() {
443-
let client = Client::test_builder().monitor_events().build().await;
443+
let client = Client::for_test().monitor_events().await;
444444
let coll: Collection<Document> = client.database("test").collection(function_name!());
445445

446446
coll.drop().await.unwrap();
@@ -487,7 +487,7 @@ async fn command_contains_write_concern_delete_many() {
487487
#[tokio::test]
488488
#[function_name::named]
489489
async fn command_contains_write_concern_find_one_and_delete() {
490-
let client = Client::test_builder().monitor_events().build().await;
490+
let client = Client::for_test().monitor_events().await;
491491
let coll: Collection<Document> = client.database("test").collection(function_name!());
492492

493493
coll.drop().await.unwrap();
@@ -531,7 +531,7 @@ async fn command_contains_write_concern_find_one_and_delete() {
531531
#[tokio::test]
532532
#[function_name::named]
533533
async fn command_contains_write_concern_find_one_and_replace() {
534-
let client = Client::test_builder().monitor_events().build().await;
534+
let client = Client::for_test().monitor_events().await;
535535
let coll: Collection<Document> = client.database("test").collection(function_name!());
536536

537537
coll.drop().await.unwrap();
@@ -575,7 +575,7 @@ async fn command_contains_write_concern_find_one_and_replace() {
575575
#[tokio::test]
576576
#[function_name::named]
577577
async fn command_contains_write_concern_find_one_and_update() {
578-
let client = Client::test_builder().monitor_events().build().await;
578+
let client = Client::for_test().monitor_events().await;
579579
let coll: Collection<Document> = client.database("test").collection(function_name!());
580580

581581
coll.drop().await.unwrap();
@@ -619,7 +619,7 @@ async fn command_contains_write_concern_find_one_and_update() {
619619
#[tokio::test]
620620
#[function_name::named]
621621
async fn command_contains_write_concern_aggregate() {
622-
let client = Client::test_builder().monitor_events().build().await;
622+
let client = Client::for_test().monitor_events().await;
623623
let coll: Collection<Document> = client.database("test").collection(function_name!());
624624

625625
coll.drop().await.unwrap();
@@ -669,7 +669,7 @@ async fn command_contains_write_concern_aggregate() {
669669
#[tokio::test]
670670
#[function_name::named]
671671
async fn command_contains_write_concern_drop() {
672-
let client = Client::test_builder().monitor_events().build().await;
672+
let client = Client::for_test().monitor_events().await;
673673
let coll: Collection<Document> = client.database("test").collection(function_name!());
674674

675675
coll.drop().await.unwrap();
@@ -715,7 +715,7 @@ async fn command_contains_write_concern_drop() {
715715
#[tokio::test]
716716
#[function_name::named]
717717
async fn command_contains_write_concern_create_collection() {
718-
let client = Client::test_builder().monitor_events().build().await;
718+
let client = Client::for_test().monitor_events().await;
719719
let db = client.database("test");
720720
let coll: Collection<Document> = db.collection(function_name!());
721721

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use crate::{
2020
util::fail_point::{FailPoint, FailPointMode},
2121
Event,
2222
EventClient,
23-
TestClient,
2423
},
2524
Client,
2625
ServerInfo,
@@ -128,7 +127,7 @@ async fn load_balancing_test() {
128127

129128
setup_client_options.hosts.drain(1..);
130129
setup_client_options.direct_connection = Some(true);
131-
let setup_client = TestClient::with_options(Some(setup_client_options)).await;
130+
let setup_client = Client::for_test().options(setup_client_options).await;
132131

133132
let version = VersionReq::parse(">= 4.2.9").unwrap();
134133
// blockConnection failpoint option only supported in 4.2.9+.
@@ -214,11 +213,10 @@ async fn load_balancing_test() {
214213
let hosts = options.hosts.clone();
215214
options.local_threshold = Duration::from_secs(30).into();
216215
options.min_pool_size = Some(max_pool_size);
217-
let client = Client::test_builder()
216+
let client = Client::for_test()
218217
.options(options)
219218
.monitor_events()
220219
.retain_startup_events()
221-
.build()
222220
.await;
223221

224222
let mut subscriber = client.events.stream_all();

0 commit comments

Comments
 (0)