File tree Expand file tree Collapse file tree 1 file changed +34
-1
lines changed Expand file tree Collapse file tree 1 file changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -162,8 +162,8 @@ impl Server {
162162 fd_tx = stop_listen_rx. recv( ) => {
163163 if let Some ( fd_tx) = fd_tx {
164164 fd_tx. send( incoming) . await . unwrap( ) ;
165- break ;
166165 }
166+ break ;
167167 }
168168 }
169169 }
@@ -601,3 +601,36 @@ impl HandlerContext {
601601 . ok ( ) ;
602602 }
603603}
604+
605+ #[ cfg( target_os = "linux" ) ]
606+ #[ cfg( test) ]
607+ mod tests {
608+ use super :: * ;
609+
610+ pub const SOCK_ADDR : & str = r"unix://@/tmp/ttrpc-server-unit-test" ;
611+
612+ pub fn is_socket_in_use ( sock_path : & str ) -> bool {
613+ let output = std:: process:: Command :: new ( "bash" )
614+ . args ( [ "-c" , & format ! ( "lsof -U|grep {}" , sock_path) ] )
615+ . output ( )
616+ . expect ( "Failed to execute lsof command" ) ;
617+
618+ output. status . success ( )
619+ }
620+
621+ #[ tokio:: test]
622+ async fn test_server_lifetime ( ) {
623+ let addr = SOCK_ADDR
624+ . strip_prefix ( "unix://@" )
625+ . expect ( "socket address is not expected" ) ;
626+ {
627+ let mut server = Server :: new ( ) . bind ( SOCK_ADDR ) . unwrap ( ) ;
628+ server. start ( ) . await . unwrap ( ) ;
629+ assert ! ( is_socket_in_use( addr) ) ;
630+ }
631+
632+ // Sleep to wait for shutdown of server caused by server's lifetime over
633+ tokio:: time:: sleep ( std:: time:: Duration :: from_secs ( 1 ) ) . await ;
634+ assert ! ( !is_socket_in_use( addr) ) ;
635+ }
636+ }
You can’t perform that action at this time.
0 commit comments