File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -686,3 +686,36 @@ impl HandlerContext {
686686 . ok ( ) ;
687687 }
688688}
689+
690+ #[ cfg( target_os = "linux" ) ]
691+ #[ cfg( test) ]
692+ mod tests {
693+ use super :: * ;
694+
695+ pub const SOCK_ADDR : & str = r"unix://@/tmp/ttrpc-server-unit-test" ;
696+
697+ pub fn is_socket_in_use ( sock_path : & str ) -> bool {
698+ let output = std:: process:: Command :: new ( "bash" )
699+ . args ( [ "-c" , & format ! ( "lsof -U|grep {}" , sock_path) ] )
700+ . output ( )
701+ . expect ( "Failed to execute lsof command" ) ;
702+
703+ output. status . success ( )
704+ }
705+
706+ #[ tokio:: test]
707+ async fn test_server_lifetime ( ) {
708+ let addr = SOCK_ADDR
709+ . strip_prefix ( "unix://@" )
710+ . expect ( "socket address is not expected" ) ;
711+ {
712+ let mut server = Server :: new ( ) . bind ( SOCK_ADDR ) . unwrap ( ) ;
713+ server. start ( ) . await . unwrap ( ) ;
714+ assert ! ( is_socket_in_use( addr) ) ;
715+ }
716+
717+ // Sleep to wait for shutdown of server caused by server's lifetime over
718+ tokio:: time:: sleep ( std:: time:: Duration :: from_secs ( 1 ) ) . await ;
719+ assert ! ( !is_socket_in_use( addr) ) ;
720+ }
721+ }
You can’t perform that action at this time.
0 commit comments