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;
23
23
use ttrpc:: proto:: Code ;
24
24
use ttrpc:: Client ;
25
25
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
+
26
40
fn 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 ( ) {
27
56
simple_logging:: log_to_stderr ( LevelFilter :: Trace ) ;
28
57
29
58
let c = Client :: connect ( utils:: SOCK_ADDR ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments