Skip to content

Commit d528cdb

Browse files
committed
RUST-452 Fix tests with async-std 1.6.0
1 parent 288a9a7 commit d528cdb

File tree

7 files changed

+34
-6
lines changed

7 files changed

+34
-6
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ bson = "0.14.1"
2424
chrono = "0.4.7"
2525
derivative = "2.1.1"
2626
err-derive = "0.2.3"
27-
futures = "0.3.4"
27+
futures = "0.3.5"
2828
futures-intrusive = "0.3.0"
2929
hex = "0.4.0"
3030
hmac = "0.7.1"
@@ -48,7 +48,7 @@ webpki = "0.21.0"
4848
webpki-roots = "0.18.0"
4949

5050
[dependencies.async-std]
51-
version = "1.5.0"
51+
version = "1.6.0"
5252
optional = true
5353

5454
[dependencies.pbkdf2]

src/client/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ impl Client {
211211
)
212212
}
213213

214+
#[cfg(test)]
215+
pub(crate) async fn num_sessions_in_pool(&self) -> usize {
216+
self.inner.session_pool.len().await
217+
}
218+
214219
#[cfg(test)]
215220
pub(crate) async fn clear_session_pool(&self) {
216221
self.inner.session_pool.clear().await;

src/client/options/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,15 @@ impl ClientOptions {
668668
Ok(options)
669669
}
670670

671+
#[cfg(test)]
672+
pub(crate) fn parse_without_srv_resolution(s: &str) -> Result<Self> {
673+
let parser = ClientOptionsParser::parse(s)?;
674+
let options: Self = parser.into();
675+
options.validate()?;
676+
677+
Ok(options)
678+
}
679+
671680
/// Gets the original SRV hostname specified when this ClientOptions was parsed from a URI.
672681
pub(crate) fn original_srv_hostname(&self) -> Option<&String> {
673682
self.original_srv_hostname.as_ref()

src/client/session/pool.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ impl ServerSessionPool {
5252
}
5353
}
5454

55+
#[cfg(test)]
56+
pub(crate) async fn len(&self) -> usize {
57+
self.pool.lock().await.len()
58+
}
59+
5560
#[cfg(test)]
5661
pub(crate) async fn clear(&self) {
5762
self.pool.lock().await.clear();

src/runtime/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl AsyncRuntime {
6969
/// Run a future in the foreground, blocking on it completing.
7070
///
7171
/// This will panic if called from a sychronous context when tokio is being used.
72-
#[cfg_attr(not(feature = "sync"), cfg(test))]
72+
#[cfg(feature = "sync")]
7373
pub(crate) fn block_on<F, T>(self, fut: F) -> T
7474
where
7575
F: Future<Output = T> + Send,

src/test/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ pub(crate) use self::{
1414
use lazy_static::lazy_static;
1515

1616
use self::util::TestLock;
17-
use crate::{options::ClientOptions, RUNTIME};
17+
use crate::options::ClientOptions;
1818

1919
const MAX_POOL_SIZE: u32 = 100;
2020

2121
lazy_static! {
2222
pub(crate) static ref CLIENT_OPTIONS: ClientOptions = {
2323
let uri = std::env::var("MONGODB_URI")
2424
.unwrap_or_else(|_| "mongodb://localhost:27017".to_string());
25-
let mut options = RUNTIME.block_on(ClientOptions::parse(&uri)).unwrap();
25+
let mut options = ClientOptions::parse_without_srv_resolution(&uri).unwrap();
2626
options.max_pool_size = Some(MAX_POOL_SIZE);
2727

2828
options

src/test/util/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub use self::{
88
matchable::{assert_matches, Matchable},
99
};
1010

11-
use std::{collections::HashMap, fmt::Debug, sync::Arc};
11+
use std::{collections::HashMap, fmt::Debug, sync::Arc, time::Duration};
1212

1313
use bson::{doc, oid::ObjectId, Bson};
1414
use semver::Version;
@@ -21,6 +21,7 @@ use crate::{
2121
options::{auth::AuthMechanism, ClientOptions, CreateCollectionOptions},
2222
Client,
2323
Collection,
24+
RUNTIME,
2425
};
2526

2627
pub struct TestClient {
@@ -79,6 +80,14 @@ impl TestClient {
7980
let info: BuildInfo = bson::from_bson(Bson::Document(response)).unwrap();
8081
let server_version = Version::parse(&info.version).unwrap();
8182

83+
// Clear the implicit sessions created by the above operations so that they don't mess with
84+
// later tests.
85+
while client.num_sessions_in_pool().await < 2 {
86+
RUNTIME.delay_for(Duration::from_millis(250)).await;
87+
}
88+
89+
client.clear_session_pool().await;
90+
8291
Self {
8392
client,
8493
options,

0 commit comments

Comments
 (0)