@@ -18,12 +18,36 @@ mod utils;
1818use log:: LevelFilter ;
1919use protocols:: sync:: { agent, agent_ttrpc, health, health_ttrpc} ;
2020use std:: thread;
21+ use std:: time:: Duration ;
2122use ttrpc:: context:: { self , Context } ;
2223use ttrpc:: error:: Error ;
2324use ttrpc:: proto:: Code ;
2425use ttrpc:: Client ;
2526
27+ #[ cfg( not( target_os = "linux" ) ) ]
28+ fn get_fd_count ( ) -> usize {
29+ // currently not support get fd count
30+ 0
31+ }
32+
33+ #[ cfg( target_os = "linux" ) ]
34+ fn get_fd_count ( ) -> usize {
35+ let path = "/proc/self/fd" ;
36+ let count = std:: fs:: read_dir ( path) . unwrap ( ) . count ( ) ;
37+ println ! ( "get fd count {}" , count) ;
38+ count
39+ }
40+
2641fn main ( ) {
42+ let expected_fd_count = get_fd_count ( ) ;
43+ connect_once ( ) ;
44+ // Give some time for fd to be released in the other thread
45+ thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
46+ let current_fd_count = get_fd_count ( ) ;
47+ assert_eq ! ( current_fd_count, expected_fd_count, "check fd count" ) ;
48+ }
49+
50+ fn connect_once ( ) {
2751 simple_logging:: log_to_stderr ( LevelFilter :: Trace ) ;
2852
2953 let c = Client :: connect ( utils:: SOCK_ADDR ) . unwrap ( ) ;
@@ -53,7 +77,10 @@ fn main() {
5377 panic ! ( "not expecting an error from the example server: {:?}" , e)
5478 }
5579 Ok ( x) => {
56- panic ! ( "not expecting a OK response from the example server: {:?}" , x)
80+ panic ! (
81+ "not expecting a OK response from the example server: {:?}" ,
82+ x
83+ )
5784 }
5885 }
5986 println ! (
@@ -107,7 +134,10 @@ fn main() {
107134 panic ! ( "not expecting an error from the example server: {:?}" , e)
108135 }
109136 Ok ( s) => {
110- panic ! ( "not expecting a OK response from the example server: {:?}" , s)
137+ panic ! (
138+ "not expecting a OK response from the example server: {:?}" ,
139+ s
140+ )
111141 }
112142 } ;
113143 println ! (
@@ -116,9 +146,6 @@ fn main() {
116146 now. elapsed( )
117147 ) ;
118148
119- println ! ( "\n sleep 2 seconds ...\n " ) ;
120- thread:: sleep ( std:: time:: Duration :: from_secs ( 2 ) ) ;
121-
122149 let version = hc. version ( default_ctx ( ) , & health:: CheckRequest :: new ( ) ) ;
123150 assert_eq ! ( "mock.0.1" , version. as_ref( ) . unwrap( ) . agent_version. as_str( ) ) ;
124151 assert_eq ! ( "0.0.1" , version. as_ref( ) . unwrap( ) . grpc_version. as_str( ) ) ;
0 commit comments