Skip to content

Commit f264ca2

Browse files
committed
Wait for joint_states before running test
Signed-off-by: Paul Gesel <[email protected]>
1 parent bfd1c5f commit f264ca2

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/lab_sim/test/test_core_objectives.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import time
1+
import sys
22

33
import pytest
4+
import rclpy
45
from moveit_pro_test_utils.objective_test_fixture import (
56
ExecuteObjectiveResource,
67
execute_objective_resource as execute_objective_resource,
@@ -34,6 +35,16 @@
3435
}
3536

3637

38+
def wait_for_joint_states(timeout: int = 180):
39+
node = rclpy.create_node("test_node")
40+
start_time = node.get_clock().now()
41+
while (node.get_clock().now() - start_time).to_msg().sec < timeout:
42+
if node.count_subscribers("/joint_states") > 0:
43+
return True
44+
rclpy.spin_once(node, timeout_sec=0.1)
45+
raise TimeoutError("Timeout waiting for /joint_states to start publishing")
46+
47+
3748
@pytest.mark.parametrize(
3849
"objective_id, should_cancel",
3950
get_objective_pytest_params("lab_sim", cancel_objectives, skip_objectives),
@@ -43,4 +54,5 @@ def test_all_objectives(
4354
should_cancel: bool,
4455
execute_objective_resource: ExecuteObjectiveResource,
4556
):
57+
wait_for_joint_states()
4658
run_objective(objective_id, should_cancel, execute_objective_resource)

0 commit comments

Comments
 (0)