@@ -401,7 +401,7 @@ fn test_hiroz_add_two_ints_server_to_rcl_client() {
401401 wait_for_ready ( Duration :: from_secs ( 5 ) ) ;
402402
403403 // Start RCL client
404- let mut client = Command :: new ( "ros2" )
404+ let client = Command :: new ( "ros2" )
405405 . args ( [ "run" , "demo_nodes_cpp" , "add_two_ints_client" ] )
406406 . env ( "RMW_IMPLEMENTATION" , "rmw_zenoh_cpp" )
407407 . env ( "ZENOH_CONFIG_OVERRIDE" , router. rmw_zenoh_env ( ) )
@@ -411,21 +411,31 @@ fn test_hiroz_add_two_ints_server_to_rcl_client() {
411411 . spawn ( )
412412 . expect ( "Failed to start RCL client" ) ;
413413
414+ // Wrap the child in its ProcessGuard *before* any reaping so the guard owns
415+ // it throughout. Polling `try_wait` on a separate handle and only then
416+ // handing the (already-reaped) child to a fresh guard would let the guard's
417+ // Drop signal a process group whose PID may have been recycled. Poll through
418+ // the guard's own handle instead.
419+ let mut client_guard = ProcessGuard :: new ( client, "RCL add_two_ints client" ) ;
420+
414421 // Bound the wait on the RCL client's own exit instead of a fixed sleep,
415422 // so a slow-to-discover run fails fast with a clear message rather than
416423 // hanging the hiroz server thread (blocked on its one expected request)
417424 // until nextest's hard kill.
418425 let client_deadline = std:: time:: Instant :: now ( ) + Duration :: from_secs ( 30 ) ;
419426 let client_status = loop {
420- if let Some ( status) = client. try_wait ( ) . expect ( "Failed to poll RCL client" ) {
427+ let child = client_guard
428+ . child
429+ . as_mut ( )
430+ . expect ( "client child owned by guard" ) ;
431+ if let Some ( status) = child. try_wait ( ) . expect ( "Failed to poll RCL client" ) {
421432 break Some ( status) ;
422433 }
423434 if std:: time:: Instant :: now ( ) >= client_deadline {
424435 break None ;
425436 }
426437 thread:: sleep ( Duration :: from_millis ( 200 ) ) ;
427438 } ;
428- let _client_guard = ProcessGuard :: new ( client, "RCL add_two_ints client" ) ;
429439 // Check the exit status is actually success, not just that the process
430440 // exited -- an instantly-failing `ros2 run` (e.g. missing verb plugin,
431441 // bad args) also "exits within 30s" and would otherwise false-pass here.
0 commit comments