@@ -166,10 +166,8 @@ async fn connection_pool_smoke() -> TestResult<()> {
166166 let msg = b"Hello, world!" . to_vec ( ) ;
167167 for id in & ids {
168168 let ( cid1, res) = client. echo ( * id, msg. clone ( ) ) . await ???;
169- println ! ( "First response from {}: {:?}" , cid1, res) ;
170169 assert_eq ! ( res, msg) ;
171170 let ( cid2, res) = client. echo ( * id, msg. clone ( ) ) . await ???;
172- println ! ( "Second response from {}: {:?}" , cid2, res) ;
173171 assert_eq ! ( res, msg) ;
174172 assert_eq ! ( cid1, cid2) ;
175173 connection_ids. insert ( id, cid1) ;
@@ -183,3 +181,40 @@ async fn connection_pool_smoke() -> TestResult<()> {
183181 }
184182 Ok ( ( ) )
185183}
184+
185+ /// Tests that idle connections are being reclaimed to make room if we hit the
186+ /// maximum connection limit.
187+ #[ tokio:: test]
188+ async fn connection_pool_idle ( ) -> TestResult < ( ) > {
189+ let n = 32 ;
190+ let filter = tracing_subscriber:: EnvFilter :: from_default_env ( ) ;
191+ tracing_subscriber:: fmt ( ) . with_env_filter ( filter) . init ( ) ;
192+ let nodes = echo_servers ( n) . await ?;
193+ let ids = nodes
194+ . iter ( )
195+ . map ( |( addr, _) | addr. node_id )
196+ . collect :: < Vec < _ > > ( ) ;
197+ // set up static discovery for all addrs
198+ let discovery = StaticProvider :: from_node_info ( nodes. iter ( ) . map ( |( addr, _) | addr. clone ( ) ) ) ;
199+ // build a client endpoint that can resolve all the node ids
200+ let endpoint = iroh:: Endpoint :: builder ( )
201+ . discovery ( discovery. clone ( ) )
202+ . bind ( )
203+ . await ?;
204+ let pool = ConnectionPool :: new (
205+ endpoint. clone ( ) ,
206+ ECHO_ALPN ,
207+ Options {
208+ idle_timeout : Duration :: from_secs ( 100 ) ,
209+ max_connections : 8 ,
210+ ..test_options ( )
211+ } ,
212+ ) ;
213+ let client = EchoClient { pool } ;
214+ let msg = b"Hello, world!" . to_vec ( ) ;
215+ for id in & ids {
216+ let ( _, res) = client. echo ( * id, msg. clone ( ) ) . await ???;
217+ assert_eq ! ( res, msg) ;
218+ }
219+ Ok ( ( ) )
220+ }
0 commit comments