diff --git a/.evergreen/MSRV-Cargo.lock b/.evergreen/MSRV-Cargo.lock index b4d66d559..89501541b 100644 --- a/.evergreen/MSRV-Cargo.lock +++ b/.evergreen/MSRV-Cargo.lock @@ -243,12 +243,6 @@ dependencies = [ "syn 1.0.98", ] -[[package]] -name = "async_once" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ce4f10ea3abcd6617873bae9f91d1c5332b4a778bd9ce34d0cd517474c1de82" - [[package]] name = "atomic-waker" version = "1.0.0" @@ -1136,11 +1130,10 @@ dependencies = [ [[package]] name = "log" -version = "0.4.17" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" dependencies = [ - "cfg-if", "value-bag", ] @@ -1257,7 +1250,6 @@ dependencies = [ "async-std", "async-std-resolver", "async-trait", - "async_once", "backtrace", "base64", "bitflags", @@ -2193,6 +2185,7 @@ dependencies = [ "mio", "num_cpus", "once_cell", + "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", @@ -2499,14 +2492,10 @@ checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" [[package]] name = "value-bag" -version = "1.0.0-alpha.9" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2209b78d1249f7e6f3293657c9779fe31ced465df091bbd433a1cf88e916ec55" -dependencies = [ - "ctor", - "version_check", -] - +checksum = "4a72e1902dde2bd6441347de2b70b7f5d59bf157c6c62f0c44572607a1d55bbe" + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/Cargo.toml b/Cargo.toml index c465113f9..09a8f9ea3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -181,7 +181,6 @@ features = ["v4"] [dev-dependencies] anyhow = { version = "1.0", features = ["backtrace"] } approx = "0.5.1" -async_once = "0.2.6" backtrace = { version = "0.3.68" } ctrlc = "3.2.2" function_name = "0.2.1" @@ -194,7 +193,7 @@ serde = { version = ">= 0.0.0", features = ["rc"] } serde_json = "1.0.64" semver = "1.0.0" time = "0.3.9" -tokio = { version = ">= 0.0.0", features = ["fs"] } +tokio = { version = ">= 0.0.0", features = ["fs", "parking_lot"] } tracing-subscriber = "0.3.16" regex = "1.6.0" serde-hex = "0.1.0" diff --git a/src/client/session/test.rs b/src/client/session/test.rs index 9d88d76bc..216003d4c 100644 --- a/src/client/session/test.rs +++ b/src/client/session/test.rs @@ -14,13 +14,13 @@ use crate::{ sdam::ServerInfo, selection_criteria::SelectionCriteria, test::{ + get_client_options, log_uncaptured, Event, EventClient, EventHandler, SdamEvent, TestClient, - CLIENT_OPTIONS, }, Client, Collection, @@ -307,7 +307,7 @@ async fn cluster_time_in_commands() { } let handler = Arc::new(EventHandler::new()); - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); options.heartbeat_freq = Some(Duration::from_secs(1000)); options.command_event_handler = Some(handler.clone()); options.sdam_event_handler = Some(handler.clone()); diff --git a/src/cmap/test.rs b/src/cmap/test.rs index 07a3a2bad..ca0fe6b9d 100644 --- a/src/cmap/test.rs +++ b/src/cmap/test.rs @@ -27,12 +27,12 @@ use crate::{ test::{ assert_matches, eq_matches, + get_client_options, log_uncaptured, run_spec_test, EventClient, MatchErrExt, Matchable, - CLIENT_OPTIONS, }, }; use bson::doc; @@ -157,9 +157,9 @@ impl Executor { let (updater, mut receiver) = TopologyUpdater::channel(); let pool = ConnectionPool::new( - CLIENT_OPTIONS.get().await.hosts[0].clone(), + get_client_options().await.hosts[0].clone(), ConnectionEstablisher::new(EstablisherOptions::from_client_options( - CLIENT_OPTIONS.get().await, + get_client_options().await, )) .unwrap(), updater, @@ -433,7 +433,7 @@ async fn cmap_spec_tests() { return; } - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); if options.load_balanced.unwrap_or(false) { log_uncaptured(format!( "skipping {:?} due to load balanced topology", diff --git a/src/cmap/test/integration.rs b/src/cmap/test/integration.rs index 69dbb4dae..bc463b7ca 100644 --- a/src/cmap/test/integration.rs +++ b/src/cmap/test/integration.rs @@ -16,12 +16,12 @@ use crate::{ sdam::TopologyUpdater, selection_criteria::ReadPreference, test::{ + get_client_options, log_uncaptured, FailCommandOptions, FailPoint, FailPointMode, TestClient, - CLIENT_OPTIONS, }, }; use semver::VersionReq; @@ -40,7 +40,7 @@ struct DatabaseEntry { #[cfg_attr(feature = "tokio-runtime", tokio::test)] #[cfg_attr(feature = "async-std-runtime", async_std::test)] async fn acquire_connection_and_send_command() { - let client_options = CLIENT_OPTIONS.get().await.clone(); + let client_options = get_client_options().await.clone(); let mut pool_options = ConnectionPoolOptions::from_client_options(&client_options); pool_options.ready = Some(true); @@ -84,7 +84,7 @@ async fn acquire_connection_and_send_command() { #[cfg_attr(feature = "tokio-runtime", tokio::test)] #[cfg_attr(feature = "async-std-runtime", async_std::test)] async fn concurrent_connections() { - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); if options.load_balanced.unwrap_or(false) { log_uncaptured("skipping concurrent_connections test due to load-balanced topology"); return; @@ -115,14 +115,14 @@ async fn concurrent_connections() { .expect("failpoint should succeed"); let handler = Arc::new(EventHandler::new()); - let client_options = CLIENT_OPTIONS.get().await.clone(); + let client_options = get_client_options().await.clone(); let mut options = ConnectionPoolOptions::from_client_options(&client_options); options.cmap_event_handler = Some(handler.clone() as Arc); options.ready = Some(true); let pool = ConnectionPool::new( - CLIENT_OPTIONS.get().await.hosts[0].clone(), + get_client_options().await.hosts[0].clone(), ConnectionEstablisher::new(EstablisherOptions::from_client_options(&client_options)) .unwrap(), TopologyUpdater::channel().0, @@ -174,7 +174,7 @@ async fn concurrent_connections() { #[function_name::named] async fn connection_error_during_establishment() { - let mut client_options = CLIENT_OPTIONS.get().await.clone(); + let mut client_options = get_client_options().await.clone(); if client_options.load_balanced.unwrap_or(false) { log_uncaptured( "skipping connection_error_during_establishment test due to load-balanced topology", @@ -237,7 +237,7 @@ async fn connection_error_during_establishment() { #[function_name::named] async fn connection_error_during_operation() { - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); let handler = Arc::new(EventHandler::new()); options.cmap_event_handler = Some(handler.clone() as Arc); options.hosts.drain(1..); diff --git a/src/compression/test.rs b/src/compression/test.rs index a942bcc45..4c67e752b 100644 --- a/src/compression/test.rs +++ b/src/compression/test.rs @@ -9,7 +9,7 @@ use bson::{doc, Bson}; use crate::{ client::options::ClientOptions, compression::{Compressor, CompressorId, Decoder}, - test::{TestClient, CLIENT_OPTIONS}, + test::{get_client_options, TestClient}, }; #[cfg(feature = "zlib-compression")] @@ -67,7 +67,7 @@ fn test_snappy_compressor() { #[cfg_attr(feature = "async-std-runtime", async_std::test)] #[cfg(feature = "zlib-compression")] async fn ping_server_with_zlib_compression() { - let mut client_options = CLIENT_OPTIONS.get().await.clone(); + let mut client_options = get_client_options().await.clone(); client_options.compressors = Some(vec![Compressor::Zlib { level: Some(4) }]); send_ping_with_compression(client_options).await; } @@ -76,7 +76,7 @@ async fn ping_server_with_zlib_compression() { #[cfg_attr(feature = "async-std-runtime", async_std::test)] #[cfg(feature = "zstd-compression")] async fn ping_server_with_zstd_compression() { - let mut client_options = CLIENT_OPTIONS.get().await.clone(); + let mut client_options = get_client_options().await.clone(); client_options.compressors = Some(vec![Compressor::Zstd { level: None }]); send_ping_with_compression(client_options).await; } @@ -85,7 +85,7 @@ async fn ping_server_with_zstd_compression() { #[cfg_attr(feature = "async-std-runtime", async_std::test)] #[cfg(feature = "snappy-compression")] async fn ping_server_with_snappy_compression() { - let mut client_options = CLIENT_OPTIONS.get().await.clone(); + let mut client_options = get_client_options().await.clone(); client_options.compressors = Some(vec![Compressor::Snappy]); send_ping_with_compression(client_options).await; } @@ -98,7 +98,7 @@ async fn ping_server_with_snappy_compression() { feature = "snappy-compression" ))] async fn ping_server_with_all_compressors() { - let mut client_options = CLIENT_OPTIONS.get().await.clone(); + let mut client_options = get_client_options().await.clone(); client_options.compressors = Some(vec![ Compressor::Zlib { level: None }, Compressor::Snappy, diff --git a/src/sdam/description/topology/server_selection/test/in_window.rs b/src/sdam/description/topology/server_selection/test/in_window.rs index dfa93347d..d0a1f71cb 100644 --- a/src/sdam/description/topology/server_selection/test/in_window.rs +++ b/src/sdam/description/topology/server_selection/test/in_window.rs @@ -16,6 +16,7 @@ use crate::{ sdam::{description::topology::server_selection, Server}, selection_criteria::{ReadPreference, SelectionCriteria}, test::{ + get_client_options, log_uncaptured, run_spec_test, Event, @@ -24,7 +25,6 @@ use crate::{ FailPoint, FailPointMode, TestClient, - CLIENT_OPTIONS, }, ServerInfo, }; @@ -119,7 +119,7 @@ async fn select_in_window() { #[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))] #[cfg_attr(feature = "async-std-runtime", async_std::test)] async fn load_balancing_test() { - let mut setup_client_options = CLIENT_OPTIONS.get().await.clone(); + let mut setup_client_options = get_client_options().await.clone(); if setup_client_options.load_balanced.unwrap_or(false) { log_uncaptured("skipping load_balancing_test test due to load-balanced topology"); @@ -149,7 +149,7 @@ async fn load_balancing_test() { return; } - if CLIENT_OPTIONS.get().await.hosts.len() != 2 { + if get_client_options().await.hosts.len() != 2 { log_uncaptured("skipping load_balancing_test test due to topology not having 2 mongoses"); return; } @@ -216,7 +216,7 @@ async fn load_balancing_test() { let mut handler = EventHandler::new(); let mut subscriber = handler.subscribe(); - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); let max_pool_size = DEFAULT_MAX_POOL_SIZE; let hosts = options.hosts.clone(); options.local_threshold = Duration::from_secs(30).into(); @@ -260,7 +260,7 @@ async fn load_balancing_test() { .build(); let failpoint = FailPoint::fail_command(&["find"], FailPointMode::AlwaysOn, options); - let slow_host = CLIENT_OPTIONS.get().await.hosts[0].clone(); + let slow_host = get_client_options().await.hosts[0].clone(); let criteria = SelectionCriteria::Predicate(Arc::new(move |si| si.address() == &slow_host)); let fp_guard = setup_client .enable_failpoint(failpoint, criteria) diff --git a/src/sdam/description/topology/test/sdam.rs b/src/sdam/description/topology/test/sdam.rs index 0a3bd32b1..4c0acd4a9 100644 --- a/src/sdam/description/topology/test/sdam.rs +++ b/src/sdam/description/topology/test/sdam.rs @@ -24,6 +24,7 @@ use crate::{ }, selection_criteria::TagSet, test::{ + get_client_options, log_uncaptured, run_spec_test, Event, @@ -34,7 +35,6 @@ use crate::{ FailPointMode, SdamEvent, TestClient, - CLIENT_OPTIONS, }, }; @@ -638,7 +638,7 @@ async fn topology_closed_event_last() { #[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))] #[cfg_attr(feature = "async-std-runtime", async_std::test)] async fn heartbeat_events() { - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); options.hosts.drain(1..); options.heartbeat_freq = Some(Duration::from_millis(50)); options.app_name = "heartbeat_events".to_string().into(); @@ -721,7 +721,7 @@ async fn direct_connection() { .await .expect("failed to select secondary"); - let mut secondary_options = CLIENT_OPTIONS.get().await.clone(); + let mut secondary_options = get_client_options().await.clone(); secondary_options.hosts = vec![secondary_address]; let mut direct_false_options = secondary_options.clone(); diff --git a/src/sdam/srv_polling/test.rs b/src/sdam/srv_polling/test.rs index 403ced5fb..fac2d5792 100644 --- a/src/sdam/srv_polling/test.rs +++ b/src/sdam/srv_polling/test.rs @@ -8,7 +8,7 @@ use crate::{ options::{ClientOptions, ServerAddress}, runtime, sdam::Topology, - test::{log_uncaptured, CLIENT_OPTIONS}, + test::{get_client_options, log_uncaptured}, }; fn localhost_test_build_10gen(port: u16) -> ServerAddress { @@ -131,7 +131,7 @@ async fn no_results() { #[cfg_attr(feature = "tokio-runtime", tokio::test)] #[cfg_attr(feature = "async-std-runtime", async_std::test)] async fn load_balanced_no_srv_polling() { - if CLIENT_OPTIONS.get().await.load_balanced != Some(true) { + if get_client_options().await.load_balanced != Some(true) { log_uncaptured("skipping load_balanced_no_srv_polling due to not load balanced topology"); return; } diff --git a/src/sdam/test.rs b/src/sdam/test.rs index ae688ee67..2d1167e01 100644 --- a/src/sdam/test.rs +++ b/src/sdam/test.rs @@ -15,6 +15,7 @@ use crate::{ hello::{LEGACY_HELLO_COMMAND_NAME, LEGACY_HELLO_COMMAND_NAME_LOWERCASE}, sdam::{ServerDescription, Topology}, test::{ + get_client_options, log_uncaptured, Event, EventClient, @@ -24,7 +25,6 @@ use crate::{ FailPointMode, SdamEvent, TestClient, - CLIENT_OPTIONS, }, Client, }; @@ -32,7 +32,7 @@ use crate::{ #[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))] #[cfg_attr(feature = "async-std-runtime", async_std::test)] async fn min_heartbeat_frequency() { - let mut setup_client_options = CLIENT_OPTIONS.get().await.clone(); + let mut setup_client_options = get_client_options().await.clone(); if setup_client_options.load_balanced.unwrap_or(false) { log_uncaptured("skipping min_heartbeat_frequency test due to load-balanced topology"); return; @@ -93,7 +93,7 @@ async fn min_heartbeat_frequency() { #[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))] #[cfg_attr(feature = "async-std-runtime", async_std::test)] async fn sdam_pool_management() { - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); if options.load_balanced.unwrap_or(false) { log_uncaptured("skipping sdam_pool_management test due to load-balanced topology"); return; @@ -175,7 +175,7 @@ async fn sdam_pool_management() { #[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))] #[cfg_attr(feature = "async-std-runtime", async_std::test)] async fn hello_ok_true() { - let mut setup_client_options = CLIENT_OPTIONS.get().await.clone(); + let mut setup_client_options = get_client_options().await.clone(); setup_client_options.hosts.drain(1..); if setup_client_options.server_api.is_some() { @@ -245,7 +245,7 @@ async fn repl_set_name_mismatch() -> crate::error::Result<()> { return Ok(()); } - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); options.hosts.drain(1..); options.direct_connection = Some(true); options.repl_set_name = Some("invalid".to_string()); diff --git a/src/sync/test.rs b/src/sync/test.rs index 572c64166..7eff0c084 100644 --- a/src/sync/test.rs +++ b/src/sync/test.rs @@ -38,7 +38,7 @@ fn init_db_and_typed_coll(client: &Client, db_name: &str, coll_name: &str) -> lazy_static! { static ref CLIENT_OPTIONS: ClientOptions = - runtime::block_on(async { crate::test::CLIENT_OPTIONS.get().await.clone() }); + runtime::block_on(async { crate::test::get_client_options().await.clone() }); } #[test] diff --git a/src/test.rs b/src/test.rs index 73e60c861..378ddea6e 100644 --- a/src/test.rs +++ b/src/test.rs @@ -41,9 +41,9 @@ pub(crate) use self::{ }, }; -use async_once::AsyncOnce; use home::home_dir; use lazy_static::lazy_static; +use tokio::sync::OnceCell; #[cfg(feature = "tracing-unstable")] use self::util::TracingHandler; @@ -56,12 +56,18 @@ use crate::{ }; use std::{fs::read_to_string, str::FromStr}; +static CLIENT_OPTIONS: OnceCell = OnceCell::const_new(); +pub(crate) async fn get_client_options() -> &'static ClientOptions { + CLIENT_OPTIONS + .get_or_init(|| async { + let mut options = ClientOptions::parse_uri(&*DEFAULT_URI, None).await.unwrap(); + update_options_for_testing(&mut options); + options + }) + .await +} + lazy_static! { - pub(crate) static ref CLIENT_OPTIONS: AsyncOnce = AsyncOnce::new(async { - let mut options = ClientOptions::parse_uri(&*DEFAULT_URI, None).await.unwrap(); - update_options_for_testing(&mut options); - options - }); pub(crate) static ref DEFAULT_URI: String = get_default_uri(); pub(crate) static ref SERVER_API: Option = match std::env::var("MONGODB_API_VERSION") { diff --git a/src/test/change_stream.rs b/src/test/change_stream.rs index ed6b7a3f7..ea3e8801e 100644 --- a/src/test/change_stream.rs +++ b/src/test/change_stream.rs @@ -17,7 +17,7 @@ use crate::{ Collection, }; -use super::{log_uncaptured, EventClient, TestClient, CLIENT_OPTIONS}; +use super::{get_client_options, log_uncaptured, EventClient, TestClient}; type Result = std::result::Result>; @@ -41,7 +41,7 @@ async fn init_stream( return Ok(None); } - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); // Direct connection is needed for reliable behavior with fail points. if direct_connection && init_client.is_sharded() { options.direct_connection = Some(true); diff --git a/src/test/client.rs b/src/test/client.rs index 3e74de5ff..60399009a 100644 --- a/src/test/client.rs +++ b/src/test/client.rs @@ -13,6 +13,7 @@ use crate::{ runtime, selection_criteria::{ReadPreference, ReadPreferenceOptions, SelectionCriteria}, test::{ + get_client_options, log_uncaptured, util::TestClient, Event, @@ -21,7 +22,6 @@ use crate::{ FailPoint, FailPointMode, SdamEvent, - CLIENT_OPTIONS, SERVER_API, }, Client, @@ -108,7 +108,7 @@ async fn metadata_sent_in_handshake() { #[cfg_attr(feature = "async-std-runtime", async_std::test)] #[function_name::named] async fn connection_drop_during_read() { - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); options.max_pool_size = Some(1); let client = Client::with_options(options.clone()).unwrap(); @@ -144,7 +144,7 @@ async fn connection_drop_during_read() { #[cfg_attr(feature = "tokio-runtime", tokio::test)] #[cfg_attr(feature = "async-std-runtime", async_std::test)] async fn server_selection_timeout_message() { - if CLIENT_OPTIONS.get().await.repl_set_name.is_none() { + if get_client_options().await.repl_set_name.is_none() { log_uncaptured("skipping server_selection_timeout_message due to missing replica set name"); return; } @@ -158,7 +158,7 @@ async fn server_selection_timeout_message() { .build(), }; - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); options.server_selection_timeout = Some(Duration::from_millis(500)); let client = Client::with_options(options.clone()).unwrap(); @@ -293,7 +293,7 @@ async fn list_authorized_databases() { } for name in dbs { - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); let credential = Credential::builder() .username(format!("user_{}", name)) .password(String::from("pwd")) @@ -340,7 +340,7 @@ async fn auth_test_options( mechanism: Option, success: bool, ) { - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); options.max_pool_size = Some(1); options.credential = Credential { username: Some(user.to_string()), @@ -369,8 +369,7 @@ async fn auth_test_uri( return; } - let host = CLIENT_OPTIONS - .get() + let host = get_client_options() .await .hosts .iter() @@ -389,7 +388,7 @@ async fn auth_test_uri( mechanism_str.as_ref() ); - if let Some(ref tls_options) = CLIENT_OPTIONS.get().await.tls_options() { + if let Some(ref tls_options) = get_client_options().await.tls_options() { if let Some(true) = tls_options.allow_invalid_certificates { uri.push_str("&tlsAllowInvalidCertificates=true"); } @@ -417,7 +416,7 @@ async fn auth_test_uri( } } - if let Some(true) = CLIENT_OPTIONS.get().await.load_balanced { + if let Some(true) = get_client_options().await.load_balanced { uri.push_str("&loadBalanced=true"); } @@ -624,7 +623,7 @@ async fn x509_auth() { .await .unwrap(); - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); options.credential = Some( Credential::builder() .mechanism(AuthMechanism::MongoDbX509) @@ -720,7 +719,7 @@ async fn retry_commit_txn_check_out() { .await .unwrap(); - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); let handler = Arc::new(EventHandler::new()); options.cmap_event_handler = Some(handler.clone()); options.sdam_event_handler = Some(handler.clone()); @@ -979,7 +978,7 @@ async fn find_one_and_delete_serde_consistency() { async fn warm_connection_pool() { let client = Client::test_builder() .options({ - let mut opts = CLIENT_OPTIONS.get().await.clone(); + let mut opts = get_client_options().await.clone(); opts.min_pool_size = Some(10); opts }) diff --git a/src/test/coll.rs b/src/test/coll.rs index fda319b00..0b25194e2 100644 --- a/src/test/coll.rs +++ b/src/test/coll.rs @@ -30,9 +30,9 @@ use crate::{ results::DeleteResult, runtime, test::{ + get_client_options, log_uncaptured, util::{drop_collection, EventClient, TestClient}, - CLIENT_OPTIONS, }, Collection, IndexModel, @@ -912,7 +912,7 @@ async fn typed_returns() { #[cfg_attr(feature = "async-std-runtime", async_std::test)] #[function_name::named] async fn count_documents_with_wc() { - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); options.write_concern = WriteConcern::builder() .w(Acknowledgment::Majority) .journal(true) diff --git a/src/test/csfle.rs b/src/test/csfle.rs index 2176248b4..5a41d22d0 100644 --- a/src/test/csfle.rs +++ b/src/test/csfle.rs @@ -60,13 +60,13 @@ use crate::{ }; use super::{ + get_client_options, log_uncaptured, EventClient, FailCommandOptions, FailPoint, FailPointMode, TestClient, - CLIENT_OPTIONS, }; type Result = anyhow::Result; @@ -272,7 +272,7 @@ async fn data_key_double_encryption() -> Result<()> { }, )]; let client_encrypted = Client::encrypted_builder( - CLIENT_OPTIONS.get().await.clone(), + get_client_options().await.clone(), KV_NAMESPACE.clone(), KMS_PROVIDERS.clone(), )? @@ -455,7 +455,7 @@ async fn external_key_vault() -> Result<()> { // Setup: test options. let kv_client = if with_external_key_vault { - let mut opts = CLIENT_OPTIONS.get().await.clone(); + let mut opts = get_client_options().await.clone(); opts.credential = Some( Credential::builder() .username("fake-user".to_string()) @@ -469,7 +469,7 @@ async fn external_key_vault() -> Result<()> { // Setup: encrypted client. let client_encrypted = Client::encrypted_builder( - CLIENT_OPTIONS.get().await.clone(), + get_client_options().await.clone(), KV_NAMESPACE.clone(), LOCAL_KMS.clone(), )? @@ -565,7 +565,7 @@ async fn bson_size_limits() -> Result<()> { .await?; // Setup: encrypted client. - let mut opts = CLIENT_OPTIONS.get().await.clone(); + let mut opts = get_client_options().await.clone(); let handler = Arc::new(EventHandler::new()); let mut events = handler.subscribe(); opts.command_event_handler = Some(handler.clone()); @@ -692,7 +692,7 @@ async fn views_prohibited() -> Result<()> { // Setup: encrypted client. let client_encrypted = Client::encrypted_builder( - CLIENT_OPTIONS.get().await.clone(), + get_client_options().await.clone(), KV_NAMESPACE.clone(), LOCAL_KMS.clone(), )? @@ -793,7 +793,7 @@ async fn run_corpus_test(local_schema: bool) -> Result<()> { // Setup: encrypted client and manual encryption. let client_encrypted = { let mut enc_builder = Client::encrypted_builder( - CLIENT_OPTIONS.get().await.clone(), + get_client_options().await.clone(), KV_NAMESPACE.clone(), KMS_PROVIDERS.clone(), )? @@ -1321,7 +1321,7 @@ async fn bypass_mongocryptd_via_shared_library() -> Result<()> { // Setup: encrypted client. let client_encrypted = Client::encrypted_builder( - CLIENT_OPTIONS.get().await.clone(), + get_client_options().await.clone(), KV_NAMESPACE.clone(), LOCAL_KMS.clone(), )? @@ -1367,7 +1367,7 @@ async fn bypass_mongocryptd_via_bypass_spawn() -> Result<()> { "mongocryptdSpawnArgs": [ "--pidfilepath=bypass-spawning-mongocryptd.pid", "--port=27021"], }; let client_encrypted = Client::encrypted_builder( - CLIENT_OPTIONS.get().await.clone(), + get_client_options().await.clone(), KV_NAMESPACE.clone(), LOCAL_KMS.clone(), )? @@ -1400,7 +1400,7 @@ async fn bypass_mongocryptd_unencrypted_insert(bypass: Bypass) -> Result<()> { "mongocryptdSpawnArgs": [ "--pidfilepath=bypass-spawning-mongocryptd.pid", "--port=27021"], }; let builder = Client::encrypted_builder( - CLIENT_OPTIONS.get().await.clone(), + get_client_options().await.clone(), KV_NAMESPACE.clone(), LOCAL_KMS.clone(), )? @@ -1571,7 +1571,7 @@ impl DeadlockTestCase { // Setup let client_test = TestClient::new().await; let client_keyvault = EventClient::with_options({ - let mut opts = CLIENT_OPTIONS.get().await.clone(); + let mut opts = get_client_options().await.clone(); opts.max_pool_size = Some(1); opts }) @@ -1625,7 +1625,7 @@ impl DeadlockTestCase { // Run test case let event_handler = Arc::new(EventHandler::new()); let mut encrypted_events = event_handler.subscribe(); - let mut opts = CLIENT_OPTIONS.get().await.clone(); + let mut opts = get_client_options().await.clone(); opts.max_pool_size = Some(self.max_pool_size); opts.command_event_handler = Some(event_handler.clone()); opts.sdam_event_handler = Some(event_handler.clone()); @@ -2373,7 +2373,7 @@ async fn explicit_encryption_setup() -> Result Result<()> { }; let client_encrypted = Client::encrypted_builder( - CLIENT_OPTIONS.get().await.clone(), + get_client_options().await.clone(), KV_NAMESPACE.clone(), LOCAL_KMS.clone(), )? @@ -3278,7 +3278,7 @@ async fn range_explicit_encryption_test( )?; let encrypted_client = Client::encrypted_builder( - CLIENT_OPTIONS.get().await.clone(), + get_client_options().await.clone(), KV_NAMESPACE.clone(), LOCAL_KMS.clone(), )? @@ -3583,7 +3583,7 @@ async fn fle2_example() -> Result<()> { // Create an FLE 2 collection. let encrypted_client = Client::encrypted_builder( - CLIENT_OPTIONS.get().await.clone(), + get_client_options().await.clone(), KV_NAMESPACE.clone(), LOCAL_KMS.clone(), )? diff --git a/src/test/lambda_examples/auth.rs b/src/test/lambda_examples/auth.rs index 5de94f2e9..c494c6f5a 100644 --- a/src/test/lambda_examples/auth.rs +++ b/src/test/lambda_examples/auth.rs @@ -1,40 +1,40 @@ use crate as mongodb; // begin lambda connection example 2 -use async_once::AsyncOnce; use lambda_runtime::{service_fn, LambdaEvent}; -use lazy_static::lazy_static; use mongodb::{ bson::doc, options::{AuthMechanism, ClientOptions, Credential}, Client, }; use serde_json::Value; +use tokio::sync::OnceCell; // Initialize a global static MongoDB Client with AWS authentication. The following environment // variables should also be set: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and, optionally, // AWS_SESSION_TOKEN. -// -// The client can be accessed as follows: -// let client = MONGODB_CLIENT.get().await; -lazy_static! { - static ref MONGODB_CLIENT: AsyncOnce = AsyncOnce::new(async { - let uri = std::env::var("MONGODB_URI") - .expect("MONGODB_URI must be set to the URI of the MongoDB deployment"); - let mut options = ClientOptions::parse(uri) - .await - .expect("Failed to parse options from URI"); - let credential = Credential::builder() - .mechanism(AuthMechanism::MongoDbAws) - .build(); - options.credential = Some(credential); - Client::with_options(options).expect("Failed to create MongoDB Client") - }); +static MONGODB_CLIENT: OnceCell = OnceCell::const_new(); + +async fn get_mongodb_client() -> &'static Client { + MONGODB_CLIENT + .get_or_init(|| async { + let uri = std::env::var("MONGODB_URI") + .expect("MONGODB_URI must be set to the URI of the MongoDB deployment"); + let mut options = ClientOptions::parse(uri) + .await + .expect("Failed to parse options from URI"); + let credential = Credential::builder() + .mechanism(AuthMechanism::MongoDbAws) + .build(); + options.credential = Some(credential); + Client::with_options(options).expect("Failed to create MongoDB Client") + }) + .await } // Runs a ping operation on the "db" database and returns the response. async fn handler(_: LambdaEvent) -> Result { - let client = MONGODB_CLIENT.get().await; + let client = get_mongodb_client().await; let response = client .database("db") .run_command(doc! { "ping": 1 }, None) diff --git a/src/test/lambda_examples/no_auth.rs b/src/test/lambda_examples/no_auth.rs index 737c692f3..0172216df 100644 --- a/src/test/lambda_examples/no_auth.rs +++ b/src/test/lambda_examples/no_auth.rs @@ -1,29 +1,29 @@ use crate as mongodb; // begin lambda connection example 1 -use async_once::AsyncOnce; use lambda_runtime::{service_fn, LambdaEvent}; -use lazy_static::lazy_static; use mongodb::{bson::doc, Client}; use serde_json::Value; +use tokio::sync::OnceCell; // Initialize a global static MongoDB Client. -// -// The client can be accessed as follows: -// let client = MONGODB_CLIENT.get().await; -lazy_static! { - static ref MONGODB_CLIENT: AsyncOnce = AsyncOnce::new(async { - let uri = std::env::var("MONGODB_URI") - .expect("MONGODB_URI must be set to the URI of the MongoDB deployment"); - Client::with_uri_str(uri) - .await - .expect("Failed to create MongoDB Client") - }); +static MONGODB_CLIENT: OnceCell = OnceCell::const_new(); + +async fn get_mongodb_client() -> &'static Client { + MONGODB_CLIENT + .get_or_init(|| async { + let uri = std::env::var("MONGODB_URI") + .expect("MONGODB_URI must be set to the URI of the MongoDB deployment"); + Client::with_uri_str(uri) + .await + .expect("Failed to create MongoDB Client") + }) + .await } // Runs a ping operation on the "db" database and returns the response. async fn handler(_: LambdaEvent) -> Result { - let client = MONGODB_CLIENT.get().await; + let client = get_mongodb_client().await; let response = client .database("db") .run_command(doc! { "ping": 1 }, None) diff --git a/src/test/spec/connection_stepdown.rs b/src/test/spec/connection_stepdown.rs index 1fc6c777a..079795fd0 100644 --- a/src/test/spec/connection_stepdown.rs +++ b/src/test/spec/connection_stepdown.rs @@ -15,7 +15,7 @@ use crate::{ WriteConcern, }, runtime, - test::{log_uncaptured, util::EventClient, CLIENT_OPTIONS}, + test::{get_client_options, log_uncaptured, util::EventClient}, Collection, Database, }; @@ -25,7 +25,7 @@ async fn run_test( test: impl Fn(EventClient, Database, Collection) -> F, ) { let options = ClientOptions::builder() - .hosts(CLIENT_OPTIONS.get().await.hosts.clone()) + .hosts(get_client_options().await.hosts.clone()) .retry_writes(false) .build(); let client = EventClient::with_additional_options(Some(options), None, None, None).await; diff --git a/src/test/spec/gridfs.rs b/src/test/spec/gridfs.rs index 800ad97d8..0f393c602 100644 --- a/src/test/spec/gridfs.rs +++ b/src/test/spec/gridfs.rs @@ -9,12 +9,12 @@ use crate::{ options::{GridFsBucketOptions, GridFsUploadOptions}, runtime, test::{ + get_client_options, spec::unified_runner::run_unified_tests, FailCommandOptions, FailPoint, FailPointMode, TestClient, - CLIENT_OPTIONS, }, }; @@ -186,7 +186,7 @@ async fn upload_stream_multiple_buffers() { async fn upload_stream_errors() { let client = TestClient::new().await; let client = if client.is_sharded() { - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); options.hosts.drain(1..); TestClient::with_options(options).await } else { diff --git a/src/test/spec/initial_dns_seedlist_discovery.rs b/src/test/spec/initial_dns_seedlist_discovery.rs index 93deabefd..750ad40d8 100644 --- a/src/test/spec/initial_dns_seedlist_discovery.rs +++ b/src/test/spec/initial_dns_seedlist_discovery.rs @@ -7,7 +7,7 @@ use crate::{ client::Client, options::{ClientOptions, ResolverConfig}, runtime, - test::{log_uncaptured, run_spec_test, TestClient, CLIENT_OPTIONS}, + test::{get_client_options, log_uncaptured, run_spec_test, TestClient}, }; #[derive(Debug, Deserialize)] @@ -135,7 +135,7 @@ async fn run_test(mut test_file: TestFile) { } else { let mut options_with_tls = options.clone(); if requires_tls { - options_with_tls.tls = CLIENT_OPTIONS.get().await.tls.clone(); + options_with_tls.tls = get_client_options().await.tls.clone(); } let client = Client::with_options(options_with_tls).unwrap(); diff --git a/src/test/spec/ocsp.rs b/src/test/spec/ocsp.rs index 7484252ca..57358c62f 100644 --- a/src/test/spec/ocsp.rs +++ b/src/test/spec/ocsp.rs @@ -3,7 +3,7 @@ use std::time::Duration; use bson::doc; use crate::{ - test::{log_uncaptured, CLIENT_OPTIONS}, + test::{get_client_options, log_uncaptured}, Client, }; @@ -19,7 +19,7 @@ async fn run() { .unwrap() .to_lowercase(); - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); let mut tls_options = options.tls_options().unwrap(); options.server_selection_timeout = Duration::from_millis(200).into(); diff --git a/src/test/spec/retryable_reads.rs b/src/test/spec/retryable_reads.rs index 0e6edb6e1..20518935b 100644 --- a/src/test/spec/retryable_reads.rs +++ b/src/test/spec/retryable_reads.rs @@ -11,6 +11,7 @@ use crate::{ runtime, runtime::AsyncJoinHandle, test::{ + get_client_options, log_uncaptured, spec::{unified_runner::run_unified_tests, v2_runner::run_v2_tests}, Event, @@ -19,7 +20,6 @@ use crate::{ FailPoint, FailPointMode, TestClient, - CLIENT_OPTIONS, }, Client, }; @@ -41,7 +41,7 @@ async fn run_unified() { #[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))] #[cfg_attr(feature = "async-std-runtime", async_std::test)] async fn retry_releases_connection() { - let mut client_options = CLIENT_OPTIONS.get().await.clone(); + let mut client_options = get_client_options().await.clone(); client_options.hosts.drain(1..); client_options.retry_reads = Some(true); client_options.max_pool_size = Some(1); @@ -75,7 +75,7 @@ async fn retry_releases_connection() { async fn retry_read_pool_cleared() { let handler = Arc::new(EventHandler::new()); - let mut client_options = CLIENT_OPTIONS.get().await.clone(); + let mut client_options = get_client_options().await.clone(); client_options.retry_reads = Some(true); client_options.max_pool_size = Some(1); client_options.cmap_event_handler = Some(handler.clone() as Arc); @@ -165,7 +165,7 @@ async fn retry_read_pool_cleared() { #[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))] #[cfg_attr(feature = "async-std-runtime", async_std::test)] async fn retry_read_different_mongos() { - let mut client_options = CLIENT_OPTIONS.get().await.clone(); + let mut client_options = get_client_options().await.clone(); if client_options.repl_set_name.is_some() || client_options.hosts.len() < 2 { log_uncaptured( "skipping retry_read_different_mongos: requires sharded cluster with at least two \ @@ -237,7 +237,7 @@ async fn retry_read_same_mongos() { return; } - let mut client_options = CLIENT_OPTIONS.get().await.clone(); + let mut client_options = get_client_options().await.clone(); client_options.hosts.drain(1..); client_options.retry_reads = Some(true); let fp_guard = { diff --git a/src/test/spec/retryable_writes.rs b/src/test/spec/retryable_writes.rs index 69b473eb2..274d8bc50 100644 --- a/src/test/spec/retryable_writes.rs +++ b/src/test/spec/retryable_writes.rs @@ -22,6 +22,7 @@ use crate::{ sdam::MIN_HEARTBEAT_FREQUENCY, test::{ assert_matches, + get_client_options, log_uncaptured, run_spec_test, spec::unified_runner::run_unified_tests, @@ -33,7 +34,6 @@ use crate::{ FailPoint, FailPointMode, TestClient, - CLIENT_OPTIONS, }, Client, }; @@ -53,7 +53,7 @@ async fn run_legacy() { continue; } let mut options = test_case.client_options.unwrap_or_default(); - options.hosts = CLIENT_OPTIONS.get().await.hosts.clone(); + options.hosts = get_client_options().await.hosts.clone(); if options.heartbeat_freq.is_none() { options.heartbeat_freq = Some(MIN_HEARTBEAT_FREQUENCY); } @@ -397,7 +397,7 @@ async fn label_not_added(retry_reads: bool) { async fn retry_write_pool_cleared() { let handler = Arc::new(EventHandler::new()); - let mut client_options = CLIENT_OPTIONS.get().await.clone(); + let mut client_options = get_client_options().await.clone(); client_options.retry_writes = Some(true); client_options.max_pool_size = Some(1); client_options.cmap_event_handler = Some(handler.clone() as Arc); @@ -494,7 +494,7 @@ async fn retry_write_pool_cleared() { #[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))] #[cfg_attr(feature = "async-std-runtime", async_std::test)] async fn retry_write_retryable_write_error() { - let mut client_options = CLIENT_OPTIONS.get().await.clone(); + let mut client_options = get_client_options().await.clone(); client_options.retry_writes = Some(true); let (event_tx, event_rx) = tokio::sync::mpsc::channel::>(1); // The listener needs to be active on client startup, but also needs a handle to the client @@ -583,7 +583,7 @@ async fn retry_write_retryable_write_error() { #[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))] #[cfg_attr(feature = "async-std-runtime", async_std::test)] async fn retry_write_different_mongos() { - let mut client_options = CLIENT_OPTIONS.get().await.clone(); + let mut client_options = get_client_options().await.clone(); if client_options.repl_set_name.is_some() || client_options.hosts.len() < 2 { log_uncaptured( "skipping retry_write_different_mongos: requires sharded cluster with at least two \ @@ -656,7 +656,7 @@ async fn retry_write_same_mongos() { return; } - let mut client_options = CLIENT_OPTIONS.get().await.clone(); + let mut client_options = get_client_options().await.clone(); client_options.hosts.drain(1..); client_options.retry_writes = Some(true); let fp_guard = { diff --git a/src/test/spec/sdam.rs b/src/test/spec/sdam.rs index e519bfda6..d9d7052c6 100644 --- a/src/test/spec/sdam.rs +++ b/src/test/spec/sdam.rs @@ -6,6 +6,7 @@ use crate::{ hello::LEGACY_HELLO_COMMAND_NAME, runtime, test::{ + get_client_options, log_uncaptured, spec::unified_runner::run_unified_tests, Event, @@ -15,7 +16,6 @@ use crate::{ FailPointMode, SdamEvent, TestClient, - CLIENT_OPTIONS, }, Client, }; @@ -55,7 +55,7 @@ async fn streaming_min_heartbeat_frequency() { } let handler = Arc::new(EventHandler::new()); - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); options.heartbeat_freq = Some(Duration::from_millis(500)); options.sdam_event_handler = Some(handler.clone()); @@ -106,7 +106,7 @@ async fn heartbeat_frequency_is_respected() { } let handler = Arc::new(EventHandler::new()); - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); options.heartbeat_freq = Some(Duration::from_millis(1000)); options.sdam_event_handler = Some(handler.clone()); @@ -171,7 +171,7 @@ async fn rtt_is_updated() { let app_name = "streamingRttTest"; let handler = Arc::new(EventHandler::new()); - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); options.heartbeat_freq = Some(Duration::from_millis(500)); options.app_name = Some(app_name.to_string()); options.sdam_event_handler = Some(handler.clone()); diff --git a/src/test/spec/sessions.rs b/src/test/spec/sessions.rs index 2bdeb0b43..659bf4832 100644 --- a/src/test/spec/sessions.rs +++ b/src/test/spec/sessions.rs @@ -14,12 +14,12 @@ use crate::{ options::SessionOptions, runtime::process::Process, test::{ + get_client_options, log_uncaptured, spec::unified_runner::run_unified_tests, util::Event, EventClient, TestClient, - CLIENT_OPTIONS, }, Client, }; @@ -109,7 +109,7 @@ async fn implicit_session_after_connection() { let mut max_lsids = 0usize; for _ in 0..5 { let client = { - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); options.max_pool_size = Some(1); options.retry_writes = Some(true); options.hosts.drain(1..); diff --git a/src/test/spec/trace.rs b/src/test/spec/trace.rs index 942e496e3..e36ef2339 100644 --- a/src/test/spec/trace.rs +++ b/src/test/spec/trace.rs @@ -22,10 +22,10 @@ use crate::{ SelectionCriteria, }, test::{ + get_client_options, log_uncaptured, spec::unified_runner::run_unified_tests, TestClient, - CLIENT_OPTIONS, DEFAULT_GLOBAL_TRACING_HANDLER, SERVER_API, }, @@ -121,7 +121,7 @@ async fn command_logging_truncation_default_limit() { #[cfg_attr(feature = "tokio-runtime", tokio::test)] #[cfg_attr(feature = "async-std-runtime", async_std::test)] async fn command_logging_truncation_explicit_limit() { - let mut client_opts = CLIENT_OPTIONS.get().await.clone(); + let mut client_opts = get_client_options().await.clone(); client_opts.tracing_max_document_length_bytes = Some(5); let client = TestClient::with_options(Some(client_opts)).await; @@ -158,7 +158,7 @@ async fn command_logging_truncation_explicit_limit() { #[cfg_attr(feature = "tokio-runtime", tokio::test)] #[cfg_attr(feature = "async-std-runtime", async_std::test)] async fn command_logging_truncation_mid_codepoint() { - let mut client_opts = CLIENT_OPTIONS.get().await.clone(); + let mut client_opts = get_client_options().await.clone(); client_opts.tracing_max_document_length_bytes = Some(215); let client = TestClient::with_options(Some(client_opts)).await; // On non-standalone topologies the command includes a clusterTime and so gets truncated diff --git a/src/test/spec/transactions.rs b/src/test/spec/transactions.rs index f26e02851..0d2a9fa38 100644 --- a/src/test/spec/transactions.rs +++ b/src/test/spec/transactions.rs @@ -7,13 +7,13 @@ use crate::{ bson::{doc, Document}, error::{Error, Result, TRANSIENT_TRANSACTION_ERROR, UNKNOWN_TRANSACTION_COMMIT_RESULT}, test::{ + get_client_options, log_uncaptured, spec::{unified_runner::run_unified_tests, v2_runner::run_v2_tests}, FailCommandOptions, FailPoint, FailPointMode, TestClient, - CLIENT_OPTIONS, }, Client, Collection, @@ -201,7 +201,7 @@ async fn convenient_api_retry_timeout_callback() { #[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))] #[cfg_attr(feature = "async-std-runtime", async_std::test)] async fn convenient_api_retry_timeout_commit_unknown() { - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); if Client::test_builder().build().await.is_sharded() { options.direct_connection = Some(true); options.hosts.drain(1..); @@ -256,7 +256,7 @@ async fn convenient_api_retry_timeout_commit_unknown() { #[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))] #[cfg_attr(feature = "async-std-runtime", async_std::test)] async fn convenient_api_retry_timeout_commit_transient() { - let mut options = CLIENT_OPTIONS.get().await.clone(); + let mut options = get_client_options().await.clone(); if Client::test_builder().build().await.is_sharded() { options.direct_connection = Some(true); options.hosts.drain(1..); diff --git a/src/test/spec/unified_runner/test_runner.rs b/src/test/spec/unified_runner/test_runner.rs index b7cd92b46..02403d29f 100644 --- a/src/test/spec/unified_runner/test_runner.rs +++ b/src/test/spec/unified_runner/test_runner.rs @@ -20,6 +20,7 @@ use crate::{ runtime, sdam::{TopologyDescription, MIN_HEARTBEAT_FREQUENCY}, test::{ + get_client_options, log_uncaptured, spec::unified_runner::{ entity::EventList, @@ -30,7 +31,6 @@ use crate::{ util::FailPointGuard, EventHandler, TestClient, - CLIENT_OPTIONS, DEFAULT_URI, LOAD_BALANCED_MULTIPLE_URI, LOAD_BALANCED_SINGLE_URI, @@ -431,7 +431,7 @@ impl TestRunner { client.observe_sensitive_commands.unwrap_or(false); let server_api = client.server_api.clone().or_else(|| SERVER_API.clone()); - let given_uri = if CLIENT_OPTIONS.get().await.load_balanced.unwrap_or(false) { + let given_uri = if get_client_options().await.load_balanced.unwrap_or(false) { // for serverless testing, ignore use_multiple_mongoses. if client.use_multiple_mongoses() && !*SERVERLESS { LOAD_BALANCED_MULTIPLE_URI.as_ref().expect( diff --git a/src/test/spec/v2_runner.rs b/src/test/spec/v2_runner.rs index b1b8f0c22..a9ebe9c8c 100644 --- a/src/test/spec/v2_runner.rs +++ b/src/test/spec/v2_runner.rs @@ -19,12 +19,12 @@ use crate::{ selection_criteria::SelectionCriteria, test::{ file_level_log, + get_client_options, log_uncaptured, spec::deserialize_spec_tests, util::{get_default_name, FailPointGuard}, EventClient, TestClient, - CLIENT_OPTIONS, SERVERLESS, }, Client, @@ -194,7 +194,7 @@ impl TestContext { let mut additional_options = match &test.client_options { Some(opts) => ClientOptions::parse_uri(&opts.uri, None).await.unwrap(), None => ClientOptions::builder() - .hosts(CLIENT_OPTIONS.get().await.hosts.clone()) + .hosts(get_client_options().await.hosts.clone()) .build(), }; if additional_options.heartbeat_freq.is_none() { diff --git a/src/test/util.rs b/src/test/util.rs index 21aa18312..da08fd83f 100644 --- a/src/test/util.rs +++ b/src/test/util.rs @@ -34,7 +34,7 @@ use bson::Document; use semver::{Version, VersionReq}; use serde::{de::DeserializeOwned, Serialize}; -use super::CLIENT_OPTIONS; +use super::get_client_options; use crate::{ error::{CommandError, ErrorKind, Result}, options::{AuthMechanism, ClientOptions, CollectionOptions, CreateCollectionOptions}, @@ -137,7 +137,7 @@ impl TestClientBuilder { pub(crate) async fn build(self) -> TestClient { let mut options = match self.options { Some(options) => options, - None => CLIENT_OPTIONS.get().await.clone(), + None => get_client_options().await.clone(), }; if let Some(handler) = self.handler { @@ -463,7 +463,7 @@ impl TestClient { let is_load_balanced = options .as_ref() .and_then(|o| o.load_balanced) - .or(CLIENT_OPTIONS.get().await.load_balanced) + .or(get_client_options().await.load_balanced) .unwrap_or(false); let default_options = if is_load_balanced { // for serverless testing, ignore use_multiple_mongoses. @@ -480,7 +480,7 @@ impl TestClient { update_options_for_testing(&mut o); o } else { - CLIENT_OPTIONS.get().await.clone() + get_client_options().await.clone() }; let mut options = match options { Some(mut options) => {