@@ -46,13 +46,16 @@ fn test_dynamic_subscriber_std_msgs_string() {
4646 let router = TestRouter :: new ( ) ;
4747 println ! ( "Router endpoint: {}" , router. endpoint( ) ) ;
4848
49- // Start ros-z-console with --echo /chatter
50- let mut console = spawn_console_headless ( router. endpoint ( ) , & [ "/chatter" ] ) ;
49+ // Use unique topic name to avoid interference with other tests
50+ let topic = "/chatter_string_test" ;
51+
52+ // Start ros-z-console with --echo
53+ let mut console = spawn_console_headless ( router. endpoint ( ) , & [ topic] ) ;
5154 println ! ( "Console started" ) ;
5255
5356 // Start ros2 topic pub
5457 let _publisher = spawn_ros2_topic_pub (
55- "/chatter" ,
58+ topic ,
5659 "std_msgs/msg/String" ,
5760 "{data: \" hello from ros2\" }" ,
5861 router. port ,
@@ -81,7 +84,7 @@ fn test_dynamic_subscriber_std_msgs_string() {
8184
8285 if let Ok ( json) = serde_json:: from_str :: < Value > ( & line) {
8386 if json[ "event" ] == "topic_subscribed" {
84- assert_eq ! ( json[ "topic" ] , "/chatter" ) ;
87+ assert_eq ! ( json[ "topic" ] , topic ) ;
8588 assert_eq ! ( json[ "type_name" ] , "std_msgs/msg/String" ) ;
8689
8790 // Type hash should start with RIHS01_
@@ -109,7 +112,7 @@ fn test_dynamic_subscriber_std_msgs_string() {
109112 }
110113
111114 if json[ "event" ] == "message_received" {
112- assert_eq ! ( json[ "topic" ] , "/chatter" ) ;
115+ assert_eq ! ( json[ "topic" ] , topic ) ;
113116 assert_eq ! ( json[ "type" ] , "std_msgs/msg/String" ) ;
114117
115118 // Check that data field contains "hello from ros2"
@@ -140,7 +143,10 @@ fn test_dynamic_subscriber_sensor_msgs_laser_scan() {
140143 let router = TestRouter :: new ( ) ;
141144 println ! ( "Router endpoint: {}" , router. endpoint( ) ) ;
142145
143- let mut console = spawn_console_headless ( router. endpoint ( ) , & [ "/scan" ] ) ;
146+ // Use unique topic name to avoid interference with other tests
147+ let topic = "/scan_laserscan_test" ;
148+
149+ let mut console = spawn_console_headless ( router. endpoint ( ) , & [ topic] ) ;
144150 println ! ( "Console started" ) ;
145151
146152 let laser_scan_data = r#"{
@@ -160,7 +166,7 @@ fn test_dynamic_subscriber_sensor_msgs_laser_scan() {
160166 }"# ;
161167
162168 let _publisher = spawn_ros2_topic_pub (
163- "/scan" ,
169+ topic ,
164170 "sensor_msgs/msg/LaserScan" ,
165171 laser_scan_data,
166172 router. port ,
@@ -185,7 +191,7 @@ fn test_dynamic_subscriber_sensor_msgs_laser_scan() {
185191
186192 if let Ok ( json) = serde_json:: from_str :: < Value > ( & line) {
187193 if json[ "event" ] == "topic_subscribed" {
188- assert_eq ! ( json[ "topic" ] , "/scan" ) ;
194+ assert_eq ! ( json[ "topic" ] , topic ) ;
189195 assert_eq ! ( json[ "type_name" ] , "sensor_msgs/msg/LaserScan" ) ;
190196
191197 if let Some ( hash) = json[ "type_hash" ] . as_str ( ) {
@@ -207,7 +213,7 @@ fn test_dynamic_subscriber_sensor_msgs_laser_scan() {
207213 }
208214
209215 if json[ "event" ] == "message_received" {
210- assert_eq ! ( json[ "topic" ] , "/scan" ) ;
216+ assert_eq ! ( json[ "topic" ] , topic ) ;
211217 assert_eq ! ( json[ "type" ] , "sensor_msgs/msg/LaserScan" ) ;
212218
213219 // Verify some fields from the data
@@ -253,20 +259,24 @@ fn test_dynamic_subscriber_multiple_topics() {
253259 let router = TestRouter :: new ( ) ;
254260 println ! ( "Router endpoint: {}" , router. endpoint( ) ) ;
255261
256- // Echo both /chatter and /scan
257- let mut console = spawn_console_headless ( router. endpoint ( ) , & [ "/chatter" , "/scan" ] ) ;
262+ // Use unique topic names to avoid interference with other tests
263+ let topic1 = "/chatter_multi_test" ;
264+ let topic2 = "/scan_multi_test" ;
265+
266+ // Echo both topics
267+ let mut console = spawn_console_headless ( router. endpoint ( ) , & [ topic1, topic2] ) ;
258268 println ! ( "Console started" ) ;
259269
260270 // Publish to both topics
261271 let _pub1 = spawn_ros2_topic_pub (
262- "/chatter" ,
272+ topic1 ,
263273 "std_msgs/msg/String" ,
264274 "{data: \" multi-topic test\" }" ,
265275 router. port ,
266276 ) ;
267277
268278 let _pub2 = spawn_ros2_topic_pub (
269- "/scan" ,
279+ topic2 ,
270280 "sensor_msgs/msg/LaserScan" ,
271281 r#"{
272282 "header": {"stamp": {"sec": 0, "nanosec": 0}, "frame_id": "test"},
@@ -325,19 +335,23 @@ fn test_dynamic_subscriber_multiple_topics() {
325335 }
326336
327337 assert ! (
328- subscribed_topics. contains( "/chatter" ) ,
329- "Should subscribe to /chatter"
338+ subscribed_topics. contains( topic1) ,
339+ "Should subscribe to {}" ,
340+ topic1
330341 ) ;
331342 assert ! (
332- subscribed_topics. contains( "/scan" ) ,
333- "Should subscribe to /scan"
343+ subscribed_topics. contains( topic2) ,
344+ "Should subscribe to {}" ,
345+ topic2
334346 ) ;
335347 assert ! (
336- received_messages. contains( "/chatter" ) ,
337- "Should receive messages from /chatter"
348+ received_messages. contains( topic1) ,
349+ "Should receive messages from {}" ,
350+ topic1
338351 ) ;
339352 assert ! (
340- received_messages. contains( "/scan" ) ,
341- "Should receive messages from /scan"
353+ received_messages. contains( topic2) ,
354+ "Should receive messages from {}" ,
355+ topic2
342356 ) ;
343357}
0 commit comments