Skip to content

Commit 799f323

Browse files
RUST-1447 Cache test client metadata (#1318)
1 parent 13bd338 commit 799f323

36 files changed

+868
-854
lines changed

src/client/session/test.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use crate::{
1515
selection_criteria::SelectionCriteria,
1616
test::{
1717
get_client_options,
18+
get_primary,
1819
log_uncaptured,
20+
topology_is_standalone,
1921
util::event_buffer::EventBuffer,
2022
Event,
2123
EventClient,
@@ -195,14 +197,14 @@ macro_rules! for_each_op {
195197
/// This test also satisifies the `endSession` testing requirement of prose test 5.
196198
#[tokio::test]
197199
async fn pool_is_lifo() {
200+
if topology_is_standalone().await {
201+
return;
202+
}
203+
198204
let client = Client::for_test().await;
199205
// Wait for the implicit sessions created in TestClient::new to be returned to the pool.
200206
tokio::time::sleep(Duration::from_millis(500)).await;
201207

202-
if client.is_standalone() {
203-
return;
204-
}
205-
206208
let a = client.start_session().await.unwrap();
207209
let b = client.start_session().await.unwrap();
208210

@@ -228,8 +230,7 @@ async fn pool_is_lifo() {
228230
#[tokio::test]
229231
#[function_name::named]
230232
async fn cluster_time_in_commands() {
231-
let test_client = Client::for_test().await;
232-
if test_client.is_standalone() {
233+
if topology_is_standalone().await {
233234
log_uncaptured("skipping cluster_time_in_commands test due to standalone topology");
234235
return;
235236
}
@@ -303,7 +304,7 @@ async fn cluster_time_in_commands() {
303304

304305
// Since we need to run an insert below, ensure the single host is a primary
305306
// if we're connected to a replica set.
306-
if let Some(primary) = test_client.primary() {
307+
if let Some(primary) = get_primary().await {
307308
options.hosts = vec![primary];
308309
} else {
309310
options.hosts.drain(1..);
@@ -374,8 +375,7 @@ async fn cluster_time_in_commands() {
374375
#[tokio::test]
375376
#[function_name::named]
376377
async fn session_usage() {
377-
let client = Client::for_test().await;
378-
if client.is_standalone() {
378+
if topology_is_standalone().await {
379379
return;
380380
}
381381

@@ -401,11 +401,12 @@ async fn session_usage() {
401401
#[tokio::test]
402402
#[function_name::named]
403403
async fn implicit_session_returned_after_immediate_exhaust() {
404-
let client = Client::for_test().monitor_events().await;
405-
if client.is_standalone() {
404+
if topology_is_standalone().await {
406405
return;
407406
}
408407

408+
let client = Client::for_test().monitor_events().await;
409+
409410
let coll = client
410411
.init_db_and_coll(function_name!(), function_name!())
411412
.await;
@@ -441,11 +442,11 @@ async fn implicit_session_returned_after_immediate_exhaust() {
441442
#[tokio::test]
442443
#[function_name::named]
443444
async fn implicit_session_returned_after_exhaust_by_get_more() {
444-
let client = Client::for_test().monitor_events().await;
445-
if client.is_standalone() {
445+
if topology_is_standalone().await {
446446
return;
447447
}
448448

449+
let client = Client::for_test().monitor_events().await;
449450
let coll = client
450451
.init_db_and_coll(function_name!(), function_name!())
451452
.await;
@@ -491,14 +492,15 @@ async fn implicit_session_returned_after_exhaust_by_get_more() {
491492
#[tokio::test]
492493
#[function_name::named]
493494
async fn find_and_getmore_share_session() {
494-
let client = Client::for_test().monitor_events().await;
495-
if client.is_standalone() {
495+
if topology_is_standalone().await {
496496
log_uncaptured(
497497
"skipping find_and_getmore_share_session due to unsupported topology: Standalone",
498498
);
499499
return;
500500
}
501501

502+
let client = Client::for_test().monitor_events().await;
503+
502504
let coll = client
503505
.init_db_and_coll(function_name!(), function_name!())
504506
.await;

src/client/session/test/causal_consistency.rs

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
error::Result,
77
event::command::CommandEvent,
88
options::ReadConcern,
9-
test::log_uncaptured,
9+
test::{log_uncaptured, topology_is_standalone},
1010
Client,
1111
ClientSession,
1212
Collection,
@@ -118,31 +118,29 @@ 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::for_test().monitor_events().await;
122-
123-
if client.is_standalone() {
121+
if topology_is_standalone().await {
124122
log_uncaptured(
125123
"skipping new_session_operation_time_null due to unsupported topology: standalone",
126124
);
127125
return;
128126
}
129127

128+
let client = Client::for_test().monitor_events().await;
130129
let session = client.start_session().await.unwrap();
131130
assert!(session.operation_time().is_none());
132131
}
133132

134133
/// Test 2 from the causal consistency specification.
135134
#[tokio::test]
136-
async fn first_read_no_after_cluser_time() {
137-
let client = Client::for_test().monitor_events().await;
138-
139-
if client.is_standalone() {
135+
async fn first_read_no_after_cluster_time() {
136+
if topology_is_standalone().await {
140137
log_uncaptured(
141138
"skipping first_read_no_after_cluser_time due to unsupported topology: standalone",
142139
);
143140
return;
144141
}
145142

143+
let client = Client::for_test().monitor_events().await;
146144
for op in all_session_ops().filter(|o| o.is_read) {
147145
client.events.clone().clear_cached_events();
148146

@@ -172,13 +170,12 @@ async fn first_read_no_after_cluser_time() {
172170
/// Test 3 from the causal consistency specification.
173171
#[tokio::test]
174172
async fn first_op_update_op_time() {
175-
let client = Client::for_test().monitor_events().await;
176-
177-
if client.is_standalone() {
173+
if topology_is_standalone().await {
178174
log_uncaptured("skipping first_op_update_op_time due to unsupported topology: standalone");
179175
return;
180176
}
181177

178+
let client = Client::for_test().monitor_events().await;
182179
for op in all_session_ops() {
183180
client.events.clone().clear_cached_events();
184181

@@ -221,15 +218,15 @@ async fn first_op_update_op_time() {
221218
/// Test 4 from the causal consistency specification.
222219
#[tokio::test]
223220
async fn read_includes_after_cluster_time() {
224-
let client = Client::for_test().monitor_events().await;
225-
226-
if client.is_standalone() {
221+
if topology_is_standalone().await {
227222
log_uncaptured(
228223
"skipping read_includes_after_cluster_time due to unsupported topology: standalone",
229224
);
230225
return;
231226
}
232227

228+
let client = Client::for_test().monitor_events().await;
229+
233230
let coll = client
234231
.create_fresh_collection("causal_consistency_4", "causal_consistency_4", None)
235232
.await;
@@ -262,16 +259,15 @@ async fn read_includes_after_cluster_time() {
262259
/// Test 5 from the causal consistency specification.
263260
#[tokio::test]
264261
async fn find_after_write_includes_after_cluster_time() {
265-
let client = Client::for_test().monitor_events().await;
266-
267-
if client.is_standalone() {
262+
if topology_is_standalone().await {
268263
log_uncaptured(
269264
"skipping find_after_write_includes_after_cluster_time due to unsupported topology: \
270265
standalone",
271266
);
272267
return;
273268
}
274269

270+
let client = Client::for_test().monitor_events().await;
275271
let coll = client
276272
.create_fresh_collection("causal_consistency_5", "causal_consistency_5", None)
277273
.await;
@@ -306,16 +302,15 @@ async fn find_after_write_includes_after_cluster_time() {
306302
/// Test 6 from the causal consistency specification.
307303
#[tokio::test]
308304
async fn not_causally_consistent_omits_after_cluster_time() {
309-
let client = Client::for_test().monitor_events().await;
310-
311-
if client.is_standalone() {
305+
if topology_is_standalone().await {
312306
log_uncaptured(
313307
"skipping not_causally_consistent_omits_after_cluster_time due to unsupported \
314308
topology: standalone",
315309
);
316310
return;
317311
}
318312

313+
let client = Client::for_test().monitor_events().await;
319314
let coll = client
320315
.create_fresh_collection("causal_consistency_6", "causal_consistency_6", None)
321316
.await;
@@ -345,13 +340,12 @@ async fn not_causally_consistent_omits_after_cluster_time() {
345340
/// Test 7 from the causal consistency specification.
346341
#[tokio::test]
347342
async fn omit_after_cluster_time_standalone() {
348-
let client = Client::for_test().monitor_events().await;
349-
350-
if !client.is_standalone() {
343+
if !topology_is_standalone().await {
351344
log_uncaptured("skipping omit_after_cluster_time_standalone due to unsupported topology");
352345
return;
353346
}
354347

348+
let client = Client::for_test().monitor_events().await;
355349
let coll = client
356350
.create_fresh_collection("causal_consistency_7", "causal_consistency_7", None)
357351
.await;
@@ -381,15 +375,14 @@ async fn omit_after_cluster_time_standalone() {
381375
/// Test 8 from the causal consistency specification.
382376
#[tokio::test]
383377
async fn omit_default_read_concern_level() {
384-
let client = Client::for_test().monitor_events().await;
385-
386-
if client.is_standalone() {
378+
if topology_is_standalone().await {
387379
log_uncaptured(
388380
"skipping omit_default_read_concern_level due to unsupported topology: standalone",
389381
);
390382
return;
391383
}
392384

385+
let client = Client::for_test().monitor_events().await;
393386
let coll = client
394387
.create_fresh_collection("causal_consistency_8", "causal_consistency_8", None)
395388
.await;
@@ -421,15 +414,15 @@ async fn omit_default_read_concern_level() {
421414
/// Test 9 from the causal consistency specification.
422415
#[tokio::test]
423416
async fn test_causal_consistency_read_concern_merge() {
424-
let client = Client::for_test().monitor_events().await;
425-
if client.is_standalone() {
417+
if topology_is_standalone().await {
426418
log_uncaptured(
427419
"skipping test_causal_consistency_read_concern_merge due to unsupported topology: \
428420
standalone",
429421
);
430422
return;
431423
}
432424

425+
let client = Client::for_test().monitor_events().await;
433426
let mut session = client
434427
.start_session()
435428
.causal_consistency(true)
@@ -470,12 +463,12 @@ async fn test_causal_consistency_read_concern_merge() {
470463
/// Test 11 from the causal consistency specification.
471464
#[tokio::test]
472465
async fn omit_cluster_time_standalone() {
473-
let client = Client::for_test().monitor_events().await;
474-
if !client.is_standalone() {
466+
if !topology_is_standalone().await {
475467
log_uncaptured("skipping omit_cluster_time_standalone due to unsupported topology");
476468
return;
477469
}
478470

471+
let client = Client::for_test().monitor_events().await;
479472
let coll = client
480473
.database("causal_consistency_11")
481474
.collection::<Document>("causal_consistency_11");
@@ -489,15 +482,15 @@ async fn omit_cluster_time_standalone() {
489482
/// Test 12 from the causal consistency specification.
490483
#[tokio::test]
491484
async fn cluster_time_sent_in_commands() {
492-
let client = Client::for_test().monitor_events().await;
493-
if client.is_standalone() {
485+
if topology_is_standalone().await {
494486
log_uncaptured("skipping cluster_time_sent_in_commands due to unsupported topology");
495487
return;
496488
}
497489

490+
let client = Client::for_test().monitor_events().await;
498491
let coll = client
499-
.database("causal_consistency_12")
500-
.collection::<Document>("causal_consistency_12");
492+
.create_fresh_collection("causal_consistency_12", "causal_consistency_12", None)
493+
.await;
501494

502495
coll.find_one(doc! {}).await.unwrap();
503496

src/cmap/test.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,19 @@ async fn cmap_spec_tests() {
447447
return;
448448
}
449449

450+
if let Some(ref run_on) = test_file.run_on {
451+
let mut can_run_on = false;
452+
for requirement in run_on {
453+
if requirement.can_run_on().await {
454+
can_run_on = true;
455+
}
456+
}
457+
if !can_run_on {
458+
log_uncaptured("skipping due to runOn requirements");
459+
return;
460+
}
461+
}
462+
450463
let mut options = get_client_options().await.clone();
451464
if options.load_balanced.unwrap_or(false) {
452465
log_uncaptured(format!(
@@ -458,13 +471,6 @@ async fn cmap_spec_tests() {
458471
options.hosts.drain(1..);
459472
options.direct_connection = Some(true);
460473
let client = crate::Client::for_test().options(options).await;
461-
if let Some(ref run_on) = test_file.run_on {
462-
let can_run_on = run_on.iter().any(|run_on| run_on.can_run_on(&client));
463-
if !can_run_on {
464-
log_uncaptured("skipping due to runOn requirements");
465-
return;
466-
}
467-
}
468474

469475
let _guard = if let Some(fail_point) = test_file.fail_point.take() {
470476
Some(client.enable_fail_point(fail_point).await.unwrap())

0 commit comments

Comments
 (0)