From 008ceb84c35c2a4742a5ae71495c67af9aeba52c Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 18 Sep 2026 05:02:16 +0000 Subject: [PATCH] fix(test): retry loopback accept in stale-session poll tests macOS Cross-Platform CI failed because TcpStream::connect() can return before the listener's non-blocking accept() sees the socket. Use the existing accept_pending_connections helper in poll teardown tests and related cap tests. Co-authored-by: Alexander Wagner --- src/server/mod.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/server/mod.rs b/src/server/mod.rs index c58ac8b2..c0abc49e 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -2800,11 +2800,14 @@ mod tests { for _ in 0..2 { streams.push(std::net::TcpStream::connect(&addr).unwrap()); } - server.accept_new_connections(); - assert_eq!(server.connections.len(), 2); + accept_pending_connections(&mut server, 2); let _third = std::net::TcpStream::connect(&addr).unwrap(); - server.accept_new_connections(); + let deadline = std::time::Instant::now() + std::time::Duration::from_secs(2); + while std::time::Instant::now() < deadline { + server.accept_new_connections(); + std::thread::sleep(std::time::Duration::from_millis(1)); + } assert_eq!(server.connections.len(), 2); } @@ -2936,11 +2939,14 @@ mod tests { for _ in 0..2 { streams.push(std::net::TcpStream::connect(&addr).unwrap()); } - server.accept_new_connections(); - assert_eq!(server.connections.len(), 2); + accept_pending_connections(&mut server, 2); let _third = std::net::TcpStream::connect(&addr).unwrap(); - server.accept_new_connections(); + let deadline = std::time::Instant::now() + std::time::Duration::from_secs(2); + while std::time::Instant::now() < deadline { + server.accept_new_connections(); + std::thread::sleep(std::time::Duration::from_millis(1)); + } assert_eq!( server.connections.len(), 2, @@ -3095,8 +3101,7 @@ mod tests { let addr = format!("127.0.0.1:{port}"); let _stream = std::net::TcpStream::connect(&addr).unwrap(); - server.accept_new_connections(); - assert_eq!(server.connections.len(), 1); + accept_pending_connections(&mut server, 1); server.connections[0].state = ConnState::Handshake; server.connections[0] @@ -3140,8 +3145,7 @@ mod tests { let addr = format!("127.0.0.1:{port}"); let _stream = std::net::TcpStream::connect(&addr).unwrap(); - server.accept_new_connections(); - assert_eq!(server.connections.len(), 1); + accept_pending_connections(&mut server, 1); server.connections[0].state = ConnState::AppConnected; server.connections[0] @@ -3185,8 +3189,7 @@ mod tests { let addr = format!("127.0.0.1:{port}"); let _stream = std::net::TcpStream::connect(&addr).unwrap(); - server.accept_new_connections(); - assert_eq!(server.connections.len(), 1); + accept_pending_connections(&mut server, 1); server.connections[0].state = ConnState::Playing; server.connections[0].current_stream = Some(Box::new(crate::session::stream::Stream {