@@ -8,7 +8,7 @@ pub use self::{
8
8
matchable:: { assert_matches, Matchable } ,
9
9
} ;
10
10
11
- use std:: { collections:: HashMap , fmt:: Debug , sync:: Arc } ;
11
+ use std:: { collections:: HashMap , fmt:: Debug , sync:: Arc , time :: Duration } ;
12
12
13
13
use crate :: bson:: { doc, oid:: ObjectId , Bson } ;
14
14
use semver:: Version ;
@@ -18,6 +18,7 @@ use self::event::EventHandler;
18
18
use super :: CLIENT_OPTIONS ;
19
19
use crate :: {
20
20
error:: { CommandError , ErrorKind , Result } ,
21
+ operation:: RunCommand ,
21
22
options:: { AuthMechanism , ClientOptions , CreateCollectionOptions } ,
22
23
Client ,
23
24
Collection ,
@@ -61,18 +62,27 @@ impl TestClient {
61
62
62
63
let client = Client :: with_options ( options. clone ( ) ) . unwrap ( ) ;
63
64
65
+ // To avoid populating the session pool with leftover implicit sessions, we check out a
66
+ // session here and immediately mark it as dirty, then use it with any operations we need.
67
+ let mut session = client
68
+ . start_implicit_session_with_timeout ( Duration :: from_secs ( 60 * 60 ) )
69
+ . await ;
70
+ session. mark_dirty ( ) ;
71
+
72
+ let is_master = RunCommand :: new ( "admin" . into ( ) , doc ! { "isMaster" : 1 } , None ) . unwrap ( ) ;
73
+
64
74
let server_info = bson:: from_bson ( Bson :: Document (
65
75
client
66
- . database ( "admin" )
67
- . run_command ( doc ! { "isMaster" : 1 } , None )
76
+ . execute_operation_with_session ( is_master, & mut session)
68
77
. await
69
78
. unwrap ( ) ,
70
79
) )
71
80
. unwrap ( ) ;
72
81
82
+ let build_info = RunCommand :: new ( "test" . into ( ) , doc ! { "buildInfo" : 1 } , None ) . unwrap ( ) ;
83
+
73
84
let response = client
74
- . database ( "test" )
75
- . run_command ( doc ! { "buildInfo" : 1 } , None )
85
+ . execute_operation_with_session ( build_info, & mut session)
76
86
. await
77
87
. unwrap ( ) ;
78
88
0 commit comments