From 4343971ee59fa96fc2dc416802fdcbb7d9b3546d Mon Sep 17 00:00:00 2001 From: atsushi yano <55824710+atsushi421@users.noreply.github.com> Date: Wed, 5 Mar 2025 16:58:18 +0900 Subject: [PATCH] fix: not to check display order in e2e tests (#475) Signed-off-by: atsushi421 --- .../test/test_1to1_with_ros2sub.py | 31 +++++++++---------- src/agnocast_e2e_test/test/test_2to2.py | 28 ++++++++--------- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/agnocast_e2e_test/test/test_1to1_with_ros2sub.py b/src/agnocast_e2e_test/test/test_1to1_with_ros2sub.py index f38f2118..1b9afb18 100644 --- a/src/agnocast_e2e_test/test/test_1to1_with_ros2sub.py +++ b/src/agnocast_e2e_test/test/test_1to1_with_ros2sub.py @@ -193,30 +193,27 @@ class Test1To1(unittest.TestCase): def test_pub(self, proc_output, test_pub): with launch_testing.asserts.assertSequentialStdout(proc_output, process=test_pub) as cm: + proc_output = "".join(cm._output) + + # The display order is not guaranteed, so the message order is not checked. for i in range(EXPECT_INIT_PUB_NUM + EXPECT_PUB_NUM): - cm.assertInStdout(f"Publishing {i}.") - cm.assertInStdout("All messages published. Shutting down.") + self.assertEqual(proc_output.count(f"Publishing {i}."), 1) + self.assertEqual(proc_output.count("All messages published. Shutting down."), 1) def test_sub(self, proc_output, test_sub): with launch_testing.asserts.assertSequentialStdout(proc_output, process=test_sub) as cm: - # Check the order of messages received - for i in range(EXPECT_INIT_PUB_NUM - EXPECT_INIT_SUB_NUM, EXPECT_SUB_NUM): - cm.assertInStdout(f"Receiving {i}.") - cm.assertInStdout("All messages received. Shutting down.") + proc_output = "".join(cm._output) - # Check the number of messages received - sub_count = "".join(cm._output).count("Receiving ") - self.assertEqual(sub_count, EXPECT_INIT_SUB_NUM + EXPECT_SUB_NUM) + # The display order is not guaranteed, so the message order is not checked. + for i in range(EXPECT_INIT_PUB_NUM - EXPECT_INIT_SUB_NUM, EXPECT_SUB_NUM): + self.assertEqual(proc_output.count(f"Receiving {i}."), 1) + self.assertEqual(proc_output.count("All messages received. Shutting down."), 1) def test_ros2_sub(self, proc_output, test_ros2_sub): with launch_testing.asserts.assertSequentialStdout(proc_output, process=test_ros2_sub) as cm: - stdout_content = "".join(cm._output) + proc_output = "".join(cm._output) - # No checking of the order of messages received in ROS 2 subscription + # The display order is not guaranteed, so the message order is not checked. for i in range(EXPECT_INIT_PUB_NUM - EXPECT_INIT_ROS2_SUB_NUM, EXPECT_ROS2_SUB_NUM): - self.assertIn(f"Receiving {i}.", stdout_content) - self.assertIn("All messages received. Shutting down.", stdout_content) - - # Check the number of messages received - sub_count = stdout_content.count("Receiving ") - self.assertEqual(sub_count, EXPECT_INIT_ROS2_SUB_NUM + EXPECT_ROS2_SUB_NUM) + self.assertEqual(proc_output.count(f"Receiving {i}."), 1) + self.assertEqual(proc_output.count("All messages received. Shutting down."), 1) diff --git a/src/agnocast_e2e_test/test/test_2to2.py b/src/agnocast_e2e_test/test/test_2to2.py index 700974c7..2461d514 100644 --- a/src/agnocast_e2e_test/test/test_2to2.py +++ b/src/agnocast_e2e_test/test/test_2to2.py @@ -98,26 +98,24 @@ def common_assert(self, proc_output, container_proc, nodes): if not nodes: return - for node in nodes: - if node == 'p': - with launch_testing.asserts.assertSequentialStdout(proc_output, process=container_proc) as cm: + with launch_testing.asserts.assertSequentialStdout(proc_output, process=container_proc) as cm: + proc_output = "".join(cm._output) + + # The display order is not guaranteed, so the message order is not checked. + for node in nodes: + if node == 'p': prefix = f"[test_talker_node_{self.pub_i_}]: " for i in range(PUB_NUM): - cm.assertInStdout(f"{prefix}Publishing {i}.") - cm.assertInStdout(f"{prefix}All messages published. Shutting down.") + self.assertEqual(proc_output.count(f"{prefix}Publishing {i}."), 1) + self.assertEqual(proc_output.count( + f"{prefix}All messages published. Shutting down."), 1) self.pub_i_ += 1 - else: # s - with launch_testing.asserts.assertSequentialStdout(proc_output, process=container_proc) as cm: + else: # s prefix = f"[test_listener_node_{self.sub_i_}]: " - # Not checking the order of the messages from the different publishers for i in range(PUB_NUM): - cm.assertInStdout(f"{prefix}Receiving {i}.") - cm.assertInStdout(f"{prefix}All messages received. Shutting down.") - - # Check the number of messages received - sub_count = "".join(cm._output).count(f"{prefix}Receiving ") - self.assertEqual(sub_count, PUB_NUM*2) - + self.assertEqual(proc_output.count(f"{prefix}Receiving {i}."), 2) + self.assertEqual(proc_output.count( + f"{prefix}All messages received. Shutting down."), 1) self.sub_i_ += 1 def test_all_container(self, proc_output, container0, container1, container2, container3):