Skip to content

Commit

Permalink
fix: not to check display order in e2e tests (#475)
Browse files Browse the repository at this point in the history
Signed-off-by: atsushi421 <atsushi.yano.2@tier4.jp>
  • Loading branch information
atsushi421 authored Mar 5, 2025
1 parent 56ae9e8 commit 4343971
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 32 deletions.
31 changes: 14 additions & 17 deletions src/agnocast_e2e_test/test/test_1to1_with_ros2sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
28 changes: 13 additions & 15 deletions src/agnocast_e2e_test/test/test_2to2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 4343971

Please sign in to comment.