@@ -3218,11 +3218,17 @@ mod tests {
3218
3218
}
3219
3219
3220
3220
/// Test that we can immediately reconnect after respawning an endpoint with the same node id.
3221
+ ///
3222
+ /// Importantly, this test does not use a relay. This means there is no other path but the UDP
3223
+ /// path available. The respawned endpoint will have different direct addrs from the previous
3224
+ /// endpoint. The test attempts to ensure that this works, i.e. that the server endpoint will
3225
+ /// reply to the new addresses and not keep sending to the old UDP addresses which won't be
3226
+ /// received anymore.
3221
3227
#[ tokio:: test]
3222
3228
#[ traced_test]
3223
3229
async fn can_abort_and_reconnect ( ) -> Result {
3224
3230
const TEST_ALPN : & [ u8 ] = b"/iroh/test/1" ;
3225
- const TIMEOUT : Duration = Duration :: from_secs ( 5 ) ;
3231
+ const TIMEOUT : Duration = Duration :: from_secs ( 10 ) ;
3226
3232
3227
3233
let mut rng = & mut rand_chacha:: ChaCha12Rng :: seed_from_u64 ( 1 ) ;
3228
3234
@@ -3241,10 +3247,15 @@ mod tests {
3241
3247
let server_loop = tokio:: task:: spawn ( async move {
3242
3248
while let Some ( conn) = server. accept ( ) . await {
3243
3249
let conn = conn. accept ( ) . e ( ) ?. await . e ( ) ?;
3250
+ info ! ( "server ACCEPT" ) ;
3251
+ let mut stream = conn. open_uni ( ) . await . e ( ) ?;
3252
+ stream. write_all ( b"hi" ) . await . e ( ) ?;
3253
+ stream. finish ( ) . e ( ) ?;
3244
3254
let res = match conn. closed ( ) . await {
3245
3255
ConnectionError :: ApplicationClosed ( frame) => Ok ( u64:: from ( frame. error_code ) ) ,
3246
3256
reason => Err ( reason) ,
3247
3257
} ;
3258
+ info ! ( "server CLOSED" ) ;
3248
3259
tx. send ( res) . await . e ( ) ?;
3249
3260
}
3250
3261
Result :: < _ , n0_snafu:: Error > :: Ok ( ( ) )
@@ -3259,13 +3270,16 @@ mod tests {
3259
3270
. relay_mode ( RelayMode :: Disabled )
3260
3271
. bind ( )
3261
3272
. await ?;
3262
- info ! (
3263
- "connect client {} ({:?}) to {addr:?}" ,
3264
- ep. node_id( ) . fmt_short( ) ,
3265
- ep. bound_sockets( ) ,
3266
- ) ;
3273
+ let ipv4 = ep. bound_sockets ( ) [ 0 ] ;
3274
+ let node_id = ep. node_id ( ) . fmt_short ( ) ;
3275
+ info ! ( %node_id, %ipv4, "client CONNECT" ) ;
3267
3276
let conn = ep. connect ( addr, TEST_ALPN ) . await ?;
3277
+ info ! ( %node_id, %ipv4, "client CONNECTED" ) ;
3278
+ let mut stream = conn. accept_uni ( ) . await . e ( ) ?;
3279
+ let buf = stream. read_to_end ( 2 ) . await . e ( ) ?;
3280
+ assert_eq ! ( & buf, b"hi" ) ;
3268
3281
conn. close ( code. into ( ) , b"bye" ) ;
3282
+ info ! ( %node_id, %ipv4, "client CLOSE" ) ;
3269
3283
Ok ( ep)
3270
3284
}
3271
3285
@@ -3279,8 +3293,7 @@ mod tests {
3279
3293
. await
3280
3294
. e ( ) ??;
3281
3295
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 } ) ;
3296
+ ep. close ( ) . await ;
3284
3297
3285
3298
// Second connection
3286
3299
let ep = n0_future:: time:: timeout (
@@ -3290,9 +3303,8 @@ mod tests {
3290
3303
. await
3291
3304
. e ( ) ??;
3292
3305
assert_eq ! ( rx. recv( ) . await . unwrap( ) . unwrap( ) , 24 ) ;
3293
-
3294
- close1. await . e ( ) ?;
3295
3306
ep. close ( ) . await ;
3307
+
3296
3308
server_loop. abort ( ) ;
3297
3309
3298
3310
Ok ( ( ) )
0 commit comments