File tree Expand file tree Collapse file tree 7 files changed +34
-6
lines changed
Expand file tree Collapse file tree 7 files changed +34
-6
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ bson = "0.14.1"
2424chrono = " 0.4.7"
2525derivative = " 2.1.1"
2626err-derive = " 0.2.3"
27- futures = " 0.3.4 "
27+ futures = " 0.3.5 "
2828futures-intrusive = " 0.3.0"
2929hex = " 0.4.0"
3030hmac = " 0.7.1"
@@ -48,7 +48,7 @@ webpki = "0.21.0"
4848webpki-roots = " 0.18.0"
4949
5050[dependencies .async-std ]
51- version = " 1.5 .0"
51+ version = " 1.6 .0"
5252optional = true
5353
5454[dependencies .pbkdf2 ]
Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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 ( )
Original file line number Diff line number Diff 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 ( ) ;
Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff line change @@ -14,15 +14,15 @@ pub(crate) use self::{
1414use lazy_static:: lazy_static;
1515
1616use self :: util:: TestLock ;
17- use crate :: { options:: ClientOptions , RUNTIME } ;
17+ use crate :: options:: ClientOptions ;
1818
1919const MAX_POOL_SIZE : u32 = 100 ;
2020
2121lazy_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
Original file line number Diff line number Diff 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
1313use bson:: { doc, oid:: ObjectId , Bson } ;
1414use semver:: Version ;
@@ -21,6 +21,7 @@ use crate::{
2121 options:: { auth:: AuthMechanism , ClientOptions , CreateCollectionOptions } ,
2222 Client ,
2323 Collection ,
24+ RUNTIME ,
2425} ;
2526
2627pub 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,
You can’t perform that action at this time.
0 commit comments