1313# limitations under the License.
1414
1515from action_msgs .msg import GoalStatus
16- import pytest
1716import rclpy
1817from rclpy .action import ActionClient , ActionServer
1918from rclpy .executors import SingleThreadedExecutor
20- from rclpy .qos import qos_profile_services_default , QoSProfile , ReliabilityPolicy
19+ from rclpy .qos import qos_profile_services_default , ReliabilityPolicy
2120from test_msgs .action import Fibonacci
2221
2322
24- def test_one_goal (benchmark ):
23+ ONE_HUNDRED = 100
24+
25+
26+ def test_one_hundred_goals (benchmark ):
2527 context = rclpy .context .Context ()
2628 rclpy .init (context = context )
2729 try :
@@ -38,7 +40,7 @@ def test_one_goal(benchmark):
3840
3941 def execute_cb (goal_handle ):
4042 goal_handle .succeed ()
41- return response
43+ return Fibonacci . Result ()
4244
4345 action_server = ActionServer (
4446 node ,
@@ -55,15 +57,16 @@ def execute_cb(goal_handle):
5557 assert action_client .wait_for_server (timeout_sec = 5.0 )
5658
5759 def bm ():
58- fut = action_client .send_goal_async (Fibonacci .Goal ())
59- executor .spin_until_future_complete (fut )
60- goal_handle = fut .result () # Raises if there was an error
61- assert goal_handle .accepted
62- result_fut = goal_handle .get_result_async ()
63- executor .spin_until_future_complete (result_fut )
64- return result_fut .result ().status
60+ for _ in range (ONE_HUNDRED ):
61+ goal_fut = action_client .send_goal_async (Fibonacci .Goal ())
62+ executor .spin_until_future_complete (goal_fut )
63+ client_goal_handle = goal_fut .result ()
64+ assert client_goal_handle .accepted
65+ result_fut = client_goal_handle .get_result_async ()
66+ executor .spin_until_future_complete (result_fut )
67+ assert GoalStatus .STATUS_SUCCEEDED == result_fut .result ().status
6568
66- assert GoalStatus . STATUS_SUCCEEDED == benchmark (bm )
69+ benchmark (bm )
6770
6871 executor .shutdown ()
6972 action_client .destroy ()
0 commit comments