File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,36 @@ use ttrpc::error::Error;
2323use ttrpc:: proto:: Code ;
2424use ttrpc:: Client ;
2525
26+ #[ cfg( not( target_os = "linux" ) ) ]
27+ fn get_fd_count ( ) -> usize {
28+ // currently not support get fd count
29+ 0
30+ }
31+
32+ #[ cfg( target_os = "linux" ) ]
33+ fn get_fd_count ( ) -> usize {
34+ let path = "/proc/self/fd" ;
35+ let count = std:: fs:: read_dir ( path) . unwrap ( ) . count ( ) ;
36+ println ! ( "get fd count {}" , count) ;
37+ count
38+ }
39+
2640fn main ( ) {
41+ connect_once ( ) ;
42+ let expected_fd_count = get_fd_count ( ) ;
43+
44+ // connect 3 times and check the fd leak.
45+ for index in 0 ..3 {
46+ connect_once ( ) ;
47+ let current_fd_count = get_fd_count ( ) ;
48+ assert_eq ! (
49+ expected_fd_count, current_fd_count,
50+ "check fd count in {index}"
51+ ) ;
52+ }
53+ }
54+
55+ fn connect_once ( ) {
2756 simple_logging:: log_to_stderr ( LevelFilter :: Trace ) ;
2857
2958 let c = Client :: connect ( utils:: SOCK_ADDR ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments