@@ -3241,58 +3241,62 @@ mod tests {
3241
3241
let server_loop = tokio:: task:: spawn ( async move {
3242
3242
while let Some ( conn) = server. accept ( ) . await {
3243
3243
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 ( ) ?;
3244
3248
let res = match conn. closed ( ) . await {
3245
3249
ConnectionError :: ApplicationClosed ( frame) => Ok ( u64:: from ( frame. error_code ) ) ,
3246
3250
reason => Err ( reason) ,
3247
3251
} ;
3252
+ info ! ( "server CLOSED" ) ;
3248
3253
tx. send ( res) . await . e ( ) ?;
3249
3254
}
3250
3255
Result :: < _ , n0_snafu:: Error > :: Ok ( ( ) )
3251
3256
} ) ;
3252
3257
3253
3258
// Clients connect to the server, and immediately close the connection with a code
3254
3259
// 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 < ( ) > {
3256
3261
info ! ( "spawn client node {}" , secret_key. public( ) . fmt_short( ) ) ;
3257
3262
let ep = Endpoint :: builder ( )
3258
3263
. secret_key ( secret_key)
3259
3264
. relay_mode ( RelayMode :: Disabled )
3260
3265
. bind ( )
3261
3266
. 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" ) ;
3267
3270
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" ) ;
3268
3275
conn. close ( code. into ( ) , b"bye" ) ;
3269
- Ok ( ep)
3276
+ info ! ( %node_id, %ipv4, "client CLOSE" ) ;
3277
+ Ok ( ( ) )
3270
3278
}
3271
3279
3272
3280
let client_secret_key = SecretKey :: generate ( & mut rng) ;
3273
3281
3274
3282
// First connection
3275
- let ep = n0_future:: time:: timeout (
3283
+ n0_future:: time:: timeout (
3276
3284
TIMEOUT ,
3277
3285
connect ( client_secret_key. clone ( ) , server_addr. clone ( ) , 23 ) ,
3278
3286
)
3279
3287
. await
3280
3288
. e ( ) ??;
3281
3289
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 } ) ;
3284
3290
3285
3291
// Second connection
3286
- let ep = n0_future:: time:: timeout (
3292
+ n0_future:: time:: timeout (
3287
3293
TIMEOUT ,
3288
3294
connect ( client_secret_key. clone ( ) , server_addr. clone ( ) , 24 ) ,
3289
3295
)
3290
3296
. await
3291
3297
. e ( ) ??;
3292
3298
assert_eq ! ( rx. recv( ) . await . unwrap( ) . unwrap( ) , 24 ) ;
3293
3299
3294
- close1. await . e ( ) ?;
3295
- ep. close ( ) . await ;
3296
3300
server_loop. abort ( ) ;
3297
3301
3298
3302
Ok ( ( ) )
0 commit comments