@@ -3241,58 +3241,62 @@ mod tests {
32413241 let server_loop = tokio:: task:: spawn ( async move {
32423242 while let Some ( conn) = server. accept ( ) . await {
32433243 let conn = conn. accept ( ) . e ( ) ?. await . e ( ) ?;
3244+ info ! ( "server ACCEPT" ) ;
3245+ let mut stream = conn. open_uni ( ) . await . e ( ) ?;
3246+ stream. write_all ( b"hi" ) . await . e ( ) ?;
3247+ stream. finish ( ) . e ( ) ?;
32443248 let res = match conn. closed ( ) . await {
32453249 ConnectionError :: ApplicationClosed ( frame) => Ok ( u64:: from ( frame. error_code ) ) ,
32463250 reason => Err ( reason) ,
32473251 } ;
3252+ info ! ( "server CLOSED" ) ;
32483253 tx. send ( res) . await . e ( ) ?;
32493254 }
32503255 Result :: < _ , n0_snafu:: Error > :: Ok ( ( ) )
32513256 } ) ;
32523257
32533258 // Clients connect to the server, and immediately close the connection with a code
32543259 // and then close the endpoint.
3255- async fn connect ( secret_key : SecretKey , addr : NodeAddr , code : u32 ) -> Result < Endpoint > {
3260+ async fn connect ( secret_key : SecretKey , addr : NodeAddr , code : u32 ) -> Result < ( ) > {
32563261 info ! ( "spawn client node {}" , secret_key. public( ) . fmt_short( ) ) ;
32573262 let ep = Endpoint :: builder ( )
32583263 . secret_key ( secret_key)
32593264 . relay_mode ( RelayMode :: Disabled )
32603265 . bind ( )
32613266 . await ?;
3262- info ! (
3263- "connect client {} ({:?}) to {addr:?}" ,
3264- ep. node_id( ) . fmt_short( ) ,
3265- ep. bound_sockets( ) ,
3266- ) ;
3267+ let ipv4 = ep. bound_sockets ( ) [ 0 ] ;
3268+ let node_id = ep. node_id ( ) . fmt_short ( ) ;
3269+ info ! ( %node_id, %ipv4, "client CONNECT" ) ;
32673270 let conn = ep. connect ( addr, TEST_ALPN ) . await ?;
3271+ info ! ( %node_id, %ipv4, "client CONNECTED" ) ;
3272+ let mut stream = conn. accept_uni ( ) . await . e ( ) ?;
3273+ let buf = stream. read_to_end ( 2 ) . await . e ( ) ?;
3274+ assert_eq ! ( & buf, b"hi" ) ;
32683275 conn. close ( code. into ( ) , b"bye" ) ;
3269- Ok ( ep)
3276+ info ! ( %node_id, %ipv4, "client CLOSE" ) ;
3277+ Ok ( ( ) )
32703278 }
32713279
32723280 let client_secret_key = SecretKey :: generate ( & mut rng) ;
32733281
32743282 // First connection
3275- let ep = n0_future:: time:: timeout (
3283+ n0_future:: time:: timeout (
32763284 TIMEOUT ,
32773285 connect ( client_secret_key. clone ( ) , server_addr. clone ( ) , 23 ) ,
32783286 )
32793287 . await
32803288 . e ( ) ??;
32813289 assert_eq ! ( rx. recv( ) . await . unwrap( ) . unwrap( ) , 23 ) ;
3282- // close the endpoint in a separate task, to not lose time for our immediate respawn testing
3283- let close1 = tokio:: task:: spawn ( async move { ep. close ( ) . await } ) ;
32843290
32853291 // Second connection
3286- let ep = n0_future:: time:: timeout (
3292+ n0_future:: time:: timeout (
32873293 TIMEOUT ,
32883294 connect ( client_secret_key. clone ( ) , server_addr. clone ( ) , 24 ) ,
32893295 )
32903296 . await
32913297 . e ( ) ??;
32923298 assert_eq ! ( rx. recv( ) . await . unwrap( ) . unwrap( ) , 24 ) ;
32933299
3294- close1. await . e ( ) ?;
3295- ep. close ( ) . await ;
32963300 server_loop. abort ( ) ;
32973301
32983302 Ok ( ( ) )
0 commit comments