@@ -9,7 +9,14 @@ use tokio::process::{Child, Command};
99use tokio:: time:: timeout;
1010
1111/// Helper to start a chat server process.
12- async fn start_server ( name : & str , port : u16 , dist_port : u16 , connect : Option < & str > ) -> Child {
12+ async fn start_server (
13+ name : & str ,
14+ port : u16 ,
15+ dist_port : u16 ,
16+ ws_port : u16 ,
17+ http_port : u16 ,
18+ connect : Option < & str > ,
19+ ) -> Child {
1320 // Use the debug binary (built by cargo test)
1421 // CARGO_MANIFEST_DIR points to examples/chat, so we go up two levels to workspace root
1522 let manifest_dir = std:: path:: PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
@@ -22,16 +29,23 @@ async fn start_server(name: &str, port: u16, dist_port: u16, connect: Option<&st
2229 . arg ( "--port" )
2330 . arg ( port. to_string ( ) )
2431 . arg ( "--dist-port" )
25- . arg ( dist_port. to_string ( ) ) ;
32+ . arg ( dist_port. to_string ( ) )
33+ . arg ( "--ws-port" )
34+ . arg ( ws_port. to_string ( ) )
35+ . arg ( "--http-port" )
36+ . arg ( http_port. to_string ( ) ) ;
2637
2738 if let Some ( peer) = connect {
2839 cmd. arg ( "--connect" ) . arg ( peer) ;
2940 }
3041
31- cmd. env ( "RUST_LOG" , "info,starlang::distribution=debug" )
32- . kill_on_drop ( true )
33- . spawn ( )
34- . unwrap_or_else ( |e| panic ! ( "Failed to start server from {:?}: {}" , binary, e) )
42+ cmd. env (
43+ "RUST_LOG" ,
44+ "info,starlang::distribution=debug,chat_server::session=debug,chat_server::channel=debug" ,
45+ )
46+ . kill_on_drop ( true )
47+ . spawn ( )
48+ . unwrap_or_else ( |e| panic ! ( "Failed to start server from {:?}: {}" , binary, e) )
3549}
3650
3751/// Helper to connect a client and return the stream.
@@ -153,7 +167,7 @@ struct RoomInfo {
153167#[ tokio:: test]
154168async fn test_single_node_chat ( ) {
155169 // Start a single server
156- let mut server = start_server ( "node1" , 19999 , 19000 , None ) . await ;
170+ let mut server = start_server ( "node1" , 19999 , 19000 , 14000 , 18080 , None ) . await ;
157171
158172 // Give server time to start
159173 tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
@@ -253,11 +267,12 @@ async fn test_single_node_chat() {
253267#[ tokio:: test]
254268async fn test_cross_node_global_registry ( ) {
255269 // Start node1
256- let mut node1 = start_server ( "node1" , 29999 , 29000 , None ) . await ;
270+ let mut node1 = start_server ( "node1" , 29999 , 29000 , 24000 , 28080 , None ) . await ;
257271 tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
258272
259273 // Start node2 and connect to node1
260- let mut node2 = start_server ( "node2" , 29998 , 29001 , Some ( "127.0.0.1:29000" ) ) . await ;
274+ let mut node2 =
275+ start_server ( "node2" , 29998 , 29001 , 24001 , 28081 , Some ( "127.0.0.1:29000" ) ) . await ;
261276 tokio:: time:: sleep ( Duration :: from_secs ( 2 ) ) . await ; // Extra time for distribution handshake
262277
263278 // Connect alice to node1
@@ -284,9 +299,15 @@ async fn test_cross_node_global_registry() {
284299 resp
285300 ) ;
286301
287- // Give time for global registry to sync
302+ // Give time for global registry to sync and drain any pending messages (like UserList from PushPresenceState)
288303 tokio:: time:: sleep ( Duration :: from_millis ( 500 ) ) . await ;
289304
305+ // Drain any pending messages from Alice (like UserList sent after her own join)
306+ while let Ok ( msg) = timeout ( Duration :: from_millis ( 100 ) , read_message ( & mut alice) ) . await {
307+ let event = decode_event ( & msg) ;
308+ tracing:: debug!( "Drained pending message from Alice: {:?}" , event) ;
309+ }
310+
290311 // Connect bob to node2
291312 let mut bob = connect_client ( 29998 ) . await ;
292313 let _ = read_message ( & mut bob) . await ; // welcome
@@ -356,11 +377,12 @@ async fn test_cross_node_global_registry() {
356377#[ tokio:: test]
357378async fn test_room_list_across_nodes ( ) {
358379 // Start node1
359- let mut node1 = start_server ( "node1" , 39999 , 39000 , None ) . await ;
380+ let mut node1 = start_server ( "node1" , 39999 , 39000 , 34000 , 38080 , None ) . await ;
360381 tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
361382
362383 // Start node2 connected to node1
363- let mut node2 = start_server ( "node2" , 39998 , 39001 , Some ( "127.0.0.1:39000" ) ) . await ;
384+ let mut node2 =
385+ start_server ( "node2" , 39998 , 39001 , 34001 , 38081 , Some ( "127.0.0.1:39000" ) ) . await ;
364386 tokio:: time:: sleep ( Duration :: from_secs ( 2 ) ) . await ;
365387
366388 // Connect alice to node1 and create a room
0 commit comments