Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions src/client/session/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use crate::{
selection_criteria::SelectionCriteria,
test::{
get_client_options,
get_primary,
log_uncaptured,
topology_is_standalone,
util::event_buffer::EventBuffer,
Event,
EventClient,
Expand Down Expand Up @@ -195,14 +197,14 @@ macro_rules! for_each_op {
/// This test also satisifies the `endSession` testing requirement of prose test 5.
#[tokio::test]
async fn pool_is_lifo() {
if topology_is_standalone().await {
return;
}

let client = Client::for_test().await;
// Wait for the implicit sessions created in TestClient::new to be returned to the pool.
tokio::time::sleep(Duration::from_millis(500)).await;

if client.is_standalone() {
return;
}

let a = client.start_session().await.unwrap();
let b = client.start_session().await.unwrap();

Expand All @@ -228,8 +230,7 @@ async fn pool_is_lifo() {
#[tokio::test]
#[function_name::named]
async fn cluster_time_in_commands() {
let test_client = Client::for_test().await;
if test_client.is_standalone() {
if topology_is_standalone().await {
log_uncaptured("skipping cluster_time_in_commands test due to standalone topology");
return;
}
Expand Down Expand Up @@ -303,7 +304,7 @@ async fn cluster_time_in_commands() {

// Since we need to run an insert below, ensure the single host is a primary
// if we're connected to a replica set.
if let Some(primary) = test_client.primary() {
if let Some(primary) = get_primary().await {
options.hosts = vec![primary];
} else {
options.hosts.drain(1..);
Expand Down Expand Up @@ -374,8 +375,7 @@ async fn cluster_time_in_commands() {
#[tokio::test]
#[function_name::named]
async fn session_usage() {
let client = Client::for_test().await;
if client.is_standalone() {
if topology_is_standalone().await {
return;
}

Expand All @@ -401,11 +401,12 @@ async fn session_usage() {
#[tokio::test]
#[function_name::named]
async fn implicit_session_returned_after_immediate_exhaust() {
let client = Client::for_test().monitor_events().await;
if client.is_standalone() {
if topology_is_standalone().await {
return;
}

let client = Client::for_test().monitor_events().await;

let coll = client
.init_db_and_coll(function_name!(), function_name!())
.await;
Expand Down Expand Up @@ -441,11 +442,11 @@ async fn implicit_session_returned_after_immediate_exhaust() {
#[tokio::test]
#[function_name::named]
async fn implicit_session_returned_after_exhaust_by_get_more() {
let client = Client::for_test().monitor_events().await;
if client.is_standalone() {
if topology_is_standalone().await {
return;
}

let client = Client::for_test().monitor_events().await;
let coll = client
.init_db_and_coll(function_name!(), function_name!())
.await;
Expand Down Expand Up @@ -491,14 +492,15 @@ async fn implicit_session_returned_after_exhaust_by_get_more() {
#[tokio::test]
#[function_name::named]
async fn find_and_getmore_share_session() {
let client = Client::for_test().monitor_events().await;
if client.is_standalone() {
if topology_is_standalone().await {
log_uncaptured(
"skipping find_and_getmore_share_session due to unsupported topology: Standalone",
);
return;
}

let client = Client::for_test().monitor_events().await;

let coll = client
.init_db_and_coll(function_name!(), function_name!())
.await;
Expand Down
61 changes: 27 additions & 34 deletions src/client/session/test/causal_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
error::Result,
event::command::CommandEvent,
options::ReadConcern,
test::log_uncaptured,
test::{log_uncaptured, topology_is_standalone},
Client,
ClientSession,
Collection,
Expand Down Expand Up @@ -118,31 +118,29 @@ fn all_session_ops() -> impl Iterator<Item = Operation> {
/// Test 1 from the causal consistency specification.
#[tokio::test]
async fn new_session_operation_time_null() {
let client = Client::for_test().monitor_events().await;

if client.is_standalone() {
if topology_is_standalone().await {
log_uncaptured(
"skipping new_session_operation_time_null due to unsupported topology: standalone",
);
return;
}

let client = Client::for_test().monitor_events().await;
let session = client.start_session().await.unwrap();
assert!(session.operation_time().is_none());
}

/// Test 2 from the causal consistency specification.
#[tokio::test]
async fn first_read_no_after_cluser_time() {
let client = Client::for_test().monitor_events().await;

if client.is_standalone() {
async fn first_read_no_after_cluster_time() {
if topology_is_standalone().await {
log_uncaptured(
"skipping first_read_no_after_cluser_time due to unsupported topology: standalone",
);
return;
}

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

Expand Down Expand Up @@ -172,13 +170,12 @@ async fn first_read_no_after_cluser_time() {
/// Test 3 from the causal consistency specification.
#[tokio::test]
async fn first_op_update_op_time() {
let client = Client::for_test().monitor_events().await;

if client.is_standalone() {
if topology_is_standalone().await {
log_uncaptured("skipping first_op_update_op_time due to unsupported topology: standalone");
return;
}

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

Expand Down Expand Up @@ -221,15 +218,15 @@ async fn first_op_update_op_time() {
/// Test 4 from the causal consistency specification.
#[tokio::test]
async fn read_includes_after_cluster_time() {
let client = Client::for_test().monitor_events().await;

if client.is_standalone() {
if topology_is_standalone().await {
log_uncaptured(
"skipping read_includes_after_cluster_time due to unsupported topology: standalone",
);
return;
}

let client = Client::for_test().monitor_events().await;

let coll = client
.create_fresh_collection("causal_consistency_4", "causal_consistency_4", None)
.await;
Expand Down Expand Up @@ -262,16 +259,15 @@ async fn read_includes_after_cluster_time() {
/// Test 5 from the causal consistency specification.
#[tokio::test]
async fn find_after_write_includes_after_cluster_time() {
let client = Client::for_test().monitor_events().await;

if client.is_standalone() {
if topology_is_standalone().await {
log_uncaptured(
"skipping find_after_write_includes_after_cluster_time due to unsupported topology: \
standalone",
);
return;
}

let client = Client::for_test().monitor_events().await;
let coll = client
.create_fresh_collection("causal_consistency_5", "causal_consistency_5", None)
.await;
Expand Down Expand Up @@ -306,16 +302,15 @@ async fn find_after_write_includes_after_cluster_time() {
/// Test 6 from the causal consistency specification.
#[tokio::test]
async fn not_causally_consistent_omits_after_cluster_time() {
let client = Client::for_test().monitor_events().await;

if client.is_standalone() {
if topology_is_standalone().await {
log_uncaptured(
"skipping not_causally_consistent_omits_after_cluster_time due to unsupported \
topology: standalone",
);
return;
}

let client = Client::for_test().monitor_events().await;
let coll = client
.create_fresh_collection("causal_consistency_6", "causal_consistency_6", None)
.await;
Expand Down Expand Up @@ -345,13 +340,12 @@ async fn not_causally_consistent_omits_after_cluster_time() {
/// Test 7 from the causal consistency specification.
#[tokio::test]
async fn omit_after_cluster_time_standalone() {
let client = Client::for_test().monitor_events().await;

if !client.is_standalone() {
if !topology_is_standalone().await {
log_uncaptured("skipping omit_after_cluster_time_standalone due to unsupported topology");
return;
}

let client = Client::for_test().monitor_events().await;
let coll = client
.create_fresh_collection("causal_consistency_7", "causal_consistency_7", None)
.await;
Expand Down Expand Up @@ -381,15 +375,14 @@ async fn omit_after_cluster_time_standalone() {
/// Test 8 from the causal consistency specification.
#[tokio::test]
async fn omit_default_read_concern_level() {
let client = Client::for_test().monitor_events().await;

if client.is_standalone() {
if topology_is_standalone().await {
log_uncaptured(
"skipping omit_default_read_concern_level due to unsupported topology: standalone",
);
return;
}

let client = Client::for_test().monitor_events().await;
let coll = client
.create_fresh_collection("causal_consistency_8", "causal_consistency_8", None)
.await;
Expand Down Expand Up @@ -421,15 +414,15 @@ async fn omit_default_read_concern_level() {
/// Test 9 from the causal consistency specification.
#[tokio::test]
async fn test_causal_consistency_read_concern_merge() {
let client = Client::for_test().monitor_events().await;
if client.is_standalone() {
if topology_is_standalone().await {
log_uncaptured(
"skipping test_causal_consistency_read_concern_merge due to unsupported topology: \
standalone",
);
return;
}

let client = Client::for_test().monitor_events().await;
let mut session = client
.start_session()
.causal_consistency(true)
Expand Down Expand Up @@ -470,12 +463,12 @@ async fn test_causal_consistency_read_concern_merge() {
/// Test 11 from the causal consistency specification.
#[tokio::test]
async fn omit_cluster_time_standalone() {
let client = Client::for_test().monitor_events().await;
if !client.is_standalone() {
if !topology_is_standalone().await {
log_uncaptured("skipping omit_cluster_time_standalone due to unsupported topology");
return;
}

let client = Client::for_test().monitor_events().await;
let coll = client
.database("causal_consistency_11")
.collection::<Document>("causal_consistency_11");
Expand All @@ -489,15 +482,15 @@ async fn omit_cluster_time_standalone() {
/// Test 12 from the causal consistency specification.
#[tokio::test]
async fn cluster_time_sent_in_commands() {
let client = Client::for_test().monitor_events().await;
if client.is_standalone() {
if topology_is_standalone().await {
log_uncaptured("skipping cluster_time_sent_in_commands due to unsupported topology");
return;
}

let client = Client::for_test().monitor_events().await;
let coll = client
.database("causal_consistency_12")
.collection::<Document>("causal_consistency_12");
.create_fresh_collection("causal_consistency_12", "causal_consistency_12", None)
.await;

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

Expand Down
20 changes: 13 additions & 7 deletions src/cmap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,19 @@ async fn cmap_spec_tests() {
return;
}

if let Some(ref run_on) = test_file.run_on {
let mut can_run_on = false;
for requirement in run_on {
if requirement.can_run_on().await {
can_run_on = true;
}
}
if !can_run_on {
log_uncaptured("skipping due to runOn requirements");
return;
}
}

let mut options = get_client_options().await.clone();
if options.load_balanced.unwrap_or(false) {
log_uncaptured(format!(
Expand All @@ -458,13 +471,6 @@ async fn cmap_spec_tests() {
options.hosts.drain(1..);
options.direct_connection = Some(true);
let client = crate::Client::for_test().options(options).await;
if let Some(ref run_on) = test_file.run_on {
let can_run_on = run_on.iter().any(|run_on| run_on.can_run_on(&client));
if !can_run_on {
log_uncaptured("skipping due to runOn requirements");
return;
}
}

let _guard = if let Some(fail_point) = test_file.fail_point.take() {
Some(client.enable_fail_point(fail_point).await.unwrap())
Expand Down
Loading