Skip to content

Commit bc522bd

Browse files
check_controllers_running: Make timeout a parameter (#2278)
1 parent d2ae456 commit bc522bd

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

controller_manager/controller_manager/test_utils.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@
3636

3737

3838
def check_node_running(node, node_name, timeout=5.0):
39+
"""
40+
Checks if a node with the specified name is running within a given timeout.
41+
42+
Args:
43+
node (Node): The ROS 2 node instance to use for discovering nodes.
44+
node_name (str): The name of the node to check for.
45+
timeout (float, optional): The maximum time to wait for the node to appear, in seconds. Defaults to 5.0.
46+
47+
Raises:
48+
AssertionError: If the node with the specified name is not found within the timeout period.
49+
"""
3950

4051
start = time.time()
4152
found = False
@@ -45,15 +56,16 @@ def check_node_running(node, node_name, timeout=5.0):
4556
assert found, f"{node_name} not found!"
4657

4758

48-
def check_controllers_running(node, cnames, namespace="", state="active"):
59+
def check_controllers_running(node, cnames, namespace="", state="active", timeout=10.0):
4960
"""
5061
Check if the specified controllers are running on the given node.
5162
5263
Args:
53-
node (Node): The ROS2 node instance to check for controllers.
64+
node (Node): The ROS 2 node instance to use for discovering controllers.
5465
cnames (list of str): List of controller names to check.
5566
namespace (str, optional): The namespace in which to look for controllers. Defaults to "".
5667
state (str, optional): The desired state of the controllers. Defaults to "active".
68+
timeout (float, optional): The maximum time to wait for the node to appear, in seconds. Defaults to 10.0.
5769
5870
Raises:
5971
AssertionError: If any of the specified controllers are not found or not in the desired state within the timeout period.
@@ -72,7 +84,7 @@ def check_controllers_running(node, cnames, namespace="", state="active"):
7284
else:
7385
namespace_api = "/"
7486

75-
while time.time() - start < 10.0 and not all(found.values()):
87+
while time.time() - start < timeout and not all(found.values()):
7688
node_names_namespaces = node.get_node_names_and_namespaces()
7789
for cname in cnames:
7890
if any(name == cname and ns == namespace_api for name, ns in node_names_namespaces):
@@ -92,7 +104,7 @@ def check_controllers_running(node, cnames, namespace="", state="active"):
92104
cm = namespace + "controller_manager"
93105
else:
94106
cm = namespace + "/controller_manager"
95-
while time.time() - start < 10.0 and not all(found.values()):
107+
while time.time() - start < timeout and not all(found.values()):
96108
controllers = list_controllers(node, cm, 5.0).controller
97109
assert controllers, "No controllers found!"
98110
for c in controllers:

0 commit comments

Comments
 (0)