Skip to content

Commit e02bb47

Browse files
authored
RUST-1804 Replace async_once with tokio::sync::OnceCell (#992)
1 parent 3172142 commit e02bb47

File tree

31 files changed

+158
-165
lines changed

31 files changed

+158
-165
lines changed

.evergreen/MSRV-Cargo.lock

Lines changed: 6 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ features = ["v4"]
181181
[dev-dependencies]
182182
anyhow = { version = "1.0", features = ["backtrace"] }
183183
approx = "0.5.1"
184-
async_once = "0.2.6"
185184
backtrace = { version = "0.3.68" }
186185
ctrlc = "3.2.2"
187186
function_name = "0.2.1"
@@ -194,7 +193,7 @@ serde = { version = ">= 0.0.0", features = ["rc"] }
194193
serde_json = "1.0.64"
195194
semver = "1.0.0"
196195
time = "0.3.9"
197-
tokio = { version = ">= 0.0.0", features = ["fs"] }
196+
tokio = { version = ">= 0.0.0", features = ["fs", "parking_lot"] }
198197
tracing-subscriber = "0.3.16"
199198
regex = "1.6.0"
200199
serde-hex = "0.1.0"

src/client/session/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ use crate::{
1414
sdam::ServerInfo,
1515
selection_criteria::SelectionCriteria,
1616
test::{
17+
get_client_options,
1718
log_uncaptured,
1819
Event,
1920
EventClient,
2021
EventHandler,
2122
SdamEvent,
2223
TestClient,
23-
CLIENT_OPTIONS,
2424
},
2525
Client,
2626
Collection,
@@ -307,7 +307,7 @@ async fn cluster_time_in_commands() {
307307
}
308308

309309
let handler = Arc::new(EventHandler::new());
310-
let mut options = CLIENT_OPTIONS.get().await.clone();
310+
let mut options = get_client_options().await.clone();
311311
options.heartbeat_freq = Some(Duration::from_secs(1000));
312312
options.command_event_handler = Some(handler.clone());
313313
options.sdam_event_handler = Some(handler.clone());

src/cmap/test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ use crate::{
2727
test::{
2828
assert_matches,
2929
eq_matches,
30+
get_client_options,
3031
log_uncaptured,
3132
run_spec_test,
3233
EventClient,
3334
MatchErrExt,
3435
Matchable,
35-
CLIENT_OPTIONS,
3636
},
3737
};
3838
use bson::doc;
@@ -157,9 +157,9 @@ impl Executor {
157157
let (updater, mut receiver) = TopologyUpdater::channel();
158158

159159
let pool = ConnectionPool::new(
160-
CLIENT_OPTIONS.get().await.hosts[0].clone(),
160+
get_client_options().await.hosts[0].clone(),
161161
ConnectionEstablisher::new(EstablisherOptions::from_client_options(
162-
CLIENT_OPTIONS.get().await,
162+
get_client_options().await,
163163
))
164164
.unwrap(),
165165
updater,
@@ -433,7 +433,7 @@ async fn cmap_spec_tests() {
433433
return;
434434
}
435435

436-
let mut options = CLIENT_OPTIONS.get().await.clone();
436+
let mut options = get_client_options().await.clone();
437437
if options.load_balanced.unwrap_or(false) {
438438
log_uncaptured(format!(
439439
"skipping {:?} due to load balanced topology",

src/cmap/test/integration.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ use crate::{
1616
sdam::TopologyUpdater,
1717
selection_criteria::ReadPreference,
1818
test::{
19+
get_client_options,
1920
log_uncaptured,
2021
FailCommandOptions,
2122
FailPoint,
2223
FailPointMode,
2324
TestClient,
24-
CLIENT_OPTIONS,
2525
},
2626
};
2727
use semver::VersionReq;
@@ -40,7 +40,7 @@ struct DatabaseEntry {
4040
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
4141
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
4242
async fn acquire_connection_and_send_command() {
43-
let client_options = CLIENT_OPTIONS.get().await.clone();
43+
let client_options = get_client_options().await.clone();
4444
let mut pool_options = ConnectionPoolOptions::from_client_options(&client_options);
4545
pool_options.ready = Some(true);
4646

@@ -84,7 +84,7 @@ async fn acquire_connection_and_send_command() {
8484
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
8585
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
8686
async fn concurrent_connections() {
87-
let mut options = CLIENT_OPTIONS.get().await.clone();
87+
let mut options = get_client_options().await.clone();
8888
if options.load_balanced.unwrap_or(false) {
8989
log_uncaptured("skipping concurrent_connections test due to load-balanced topology");
9090
return;
@@ -115,14 +115,14 @@ async fn concurrent_connections() {
115115
.expect("failpoint should succeed");
116116

117117
let handler = Arc::new(EventHandler::new());
118-
let client_options = CLIENT_OPTIONS.get().await.clone();
118+
let client_options = get_client_options().await.clone();
119119
let mut options = ConnectionPoolOptions::from_client_options(&client_options);
120120
options.cmap_event_handler =
121121
Some(handler.clone() as Arc<dyn crate::event::cmap::CmapEventHandler>);
122122
options.ready = Some(true);
123123

124124
let pool = ConnectionPool::new(
125-
CLIENT_OPTIONS.get().await.hosts[0].clone(),
125+
get_client_options().await.hosts[0].clone(),
126126
ConnectionEstablisher::new(EstablisherOptions::from_client_options(&client_options))
127127
.unwrap(),
128128
TopologyUpdater::channel().0,
@@ -174,7 +174,7 @@ async fn concurrent_connections() {
174174
#[function_name::named]
175175

176176
async fn connection_error_during_establishment() {
177-
let mut client_options = CLIENT_OPTIONS.get().await.clone();
177+
let mut client_options = get_client_options().await.clone();
178178
if client_options.load_balanced.unwrap_or(false) {
179179
log_uncaptured(
180180
"skipping connection_error_during_establishment test due to load-balanced topology",
@@ -237,7 +237,7 @@ async fn connection_error_during_establishment() {
237237
#[function_name::named]
238238

239239
async fn connection_error_during_operation() {
240-
let mut options = CLIENT_OPTIONS.get().await.clone();
240+
let mut options = get_client_options().await.clone();
241241
let handler = Arc::new(EventHandler::new());
242242
options.cmap_event_handler = Some(handler.clone() as Arc<dyn CmapEventHandler>);
243243
options.hosts.drain(1..);

src/compression/test.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use bson::{doc, Bson};
99
use crate::{
1010
client::options::ClientOptions,
1111
compression::{Compressor, CompressorId, Decoder},
12-
test::{TestClient, CLIENT_OPTIONS},
12+
test::{get_client_options, TestClient},
1313
};
1414

1515
#[cfg(feature = "zlib-compression")]
@@ -67,7 +67,7 @@ fn test_snappy_compressor() {
6767
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
6868
#[cfg(feature = "zlib-compression")]
6969
async fn ping_server_with_zlib_compression() {
70-
let mut client_options = CLIENT_OPTIONS.get().await.clone();
70+
let mut client_options = get_client_options().await.clone();
7171
client_options.compressors = Some(vec![Compressor::Zlib { level: Some(4) }]);
7272
send_ping_with_compression(client_options).await;
7373
}
@@ -76,7 +76,7 @@ async fn ping_server_with_zlib_compression() {
7676
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
7777
#[cfg(feature = "zstd-compression")]
7878
async fn ping_server_with_zstd_compression() {
79-
let mut client_options = CLIENT_OPTIONS.get().await.clone();
79+
let mut client_options = get_client_options().await.clone();
8080
client_options.compressors = Some(vec![Compressor::Zstd { level: None }]);
8181
send_ping_with_compression(client_options).await;
8282
}
@@ -85,7 +85,7 @@ async fn ping_server_with_zstd_compression() {
8585
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
8686
#[cfg(feature = "snappy-compression")]
8787
async fn ping_server_with_snappy_compression() {
88-
let mut client_options = CLIENT_OPTIONS.get().await.clone();
88+
let mut client_options = get_client_options().await.clone();
8989
client_options.compressors = Some(vec![Compressor::Snappy]);
9090
send_ping_with_compression(client_options).await;
9191
}
@@ -98,7 +98,7 @@ async fn ping_server_with_snappy_compression() {
9898
feature = "snappy-compression"
9999
))]
100100
async fn ping_server_with_all_compressors() {
101-
let mut client_options = CLIENT_OPTIONS.get().await.clone();
101+
let mut client_options = get_client_options().await.clone();
102102
client_options.compressors = Some(vec![
103103
Compressor::Zlib { level: None },
104104
Compressor::Snappy,

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::{
1616
sdam::{description::topology::server_selection, Server},
1717
selection_criteria::{ReadPreference, SelectionCriteria},
1818
test::{
19+
get_client_options,
1920
log_uncaptured,
2021
run_spec_test,
2122
Event,
@@ -24,7 +25,6 @@ use crate::{
2425
FailPoint,
2526
FailPointMode,
2627
TestClient,
27-
CLIENT_OPTIONS,
2828
},
2929
ServerInfo,
3030
};
@@ -119,7 +119,7 @@ async fn select_in_window() {
119119
#[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))]
120120
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
121121
async fn load_balancing_test() {
122-
let mut setup_client_options = CLIENT_OPTIONS.get().await.clone();
122+
let mut setup_client_options = get_client_options().await.clone();
123123

124124
if setup_client_options.load_balanced.unwrap_or(false) {
125125
log_uncaptured("skipping load_balancing_test test due to load-balanced topology");
@@ -149,7 +149,7 @@ async fn load_balancing_test() {
149149
return;
150150
}
151151

152-
if CLIENT_OPTIONS.get().await.hosts.len() != 2 {
152+
if get_client_options().await.hosts.len() != 2 {
153153
log_uncaptured("skipping load_balancing_test test due to topology not having 2 mongoses");
154154
return;
155155
}
@@ -216,7 +216,7 @@ async fn load_balancing_test() {
216216

217217
let mut handler = EventHandler::new();
218218
let mut subscriber = handler.subscribe();
219-
let mut options = CLIENT_OPTIONS.get().await.clone();
219+
let mut options = get_client_options().await.clone();
220220
let max_pool_size = DEFAULT_MAX_POOL_SIZE;
221221
let hosts = options.hosts.clone();
222222
options.local_threshold = Duration::from_secs(30).into();
@@ -260,7 +260,7 @@ async fn load_balancing_test() {
260260
.build();
261261
let failpoint = FailPoint::fail_command(&["find"], FailPointMode::AlwaysOn, options);
262262

263-
let slow_host = CLIENT_OPTIONS.get().await.hosts[0].clone();
263+
let slow_host = get_client_options().await.hosts[0].clone();
264264
let criteria = SelectionCriteria::Predicate(Arc::new(move |si| si.address() == &slow_host));
265265
let fp_guard = setup_client
266266
.enable_failpoint(failpoint, criteria)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::{
2424
},
2525
selection_criteria::TagSet,
2626
test::{
27+
get_client_options,
2728
log_uncaptured,
2829
run_spec_test,
2930
Event,
@@ -34,7 +35,6 @@ use crate::{
3435
FailPointMode,
3536
SdamEvent,
3637
TestClient,
37-
CLIENT_OPTIONS,
3838
},
3939
};
4040

@@ -638,7 +638,7 @@ async fn topology_closed_event_last() {
638638
#[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))]
639639
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
640640
async fn heartbeat_events() {
641-
let mut options = CLIENT_OPTIONS.get().await.clone();
641+
let mut options = get_client_options().await.clone();
642642
options.hosts.drain(1..);
643643
options.heartbeat_freq = Some(Duration::from_millis(50));
644644
options.app_name = "heartbeat_events".to_string().into();
@@ -721,7 +721,7 @@ async fn direct_connection() {
721721
.await
722722
.expect("failed to select secondary");
723723

724-
let mut secondary_options = CLIENT_OPTIONS.get().await.clone();
724+
let mut secondary_options = get_client_options().await.clone();
725725
secondary_options.hosts = vec![secondary_address];
726726

727727
let mut direct_false_options = secondary_options.clone();

src/sdam/srv_polling/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
options::{ClientOptions, ServerAddress},
99
runtime,
1010
sdam::Topology,
11-
test::{log_uncaptured, CLIENT_OPTIONS},
11+
test::{get_client_options, log_uncaptured},
1212
};
1313

1414
fn localhost_test_build_10gen(port: u16) -> ServerAddress {
@@ -131,7 +131,7 @@ async fn no_results() {
131131
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
132132
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
133133
async fn load_balanced_no_srv_polling() {
134-
if CLIENT_OPTIONS.get().await.load_balanced != Some(true) {
134+
if get_client_options().await.load_balanced != Some(true) {
135135
log_uncaptured("skipping load_balanced_no_srv_polling due to not load balanced topology");
136136
return;
137137
}

0 commit comments

Comments
 (0)