Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/rai_core/rai/communication/ros2/waiters.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def wait_for_ros2_entities(

if timeout < 0:
raise ValueError("Timeout must be 0 (wait forever) or a positive value.")
if time_interval <= 0:
raise ValueError("time_interval must be a positive value.")
start_time = time.time()

while timeout == 0 or time.time() - start_time < timeout:
Expand Down
11 changes: 11 additions & 0 deletions tests/communication/ros2/test_waiters.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,14 @@ def test_wait_for_ros2_negative_timeout(

with pytest.raises(ValueError):
wait_func(connector, [name], time_interval=0.001, timeout=-0.01)


def test_wait_for_entities_rejects_non_positive_time_interval():
with pytest.raises(ValueError, match="time_interval"):
waiters.wait_for_ros2_entities(
["/x"], lambda: [], time_interval=0, timeout=1.0
)
with pytest.raises(ValueError, match="time_interval"):
waiters.wait_for_ros2_entities(
["/x"], lambda: [], time_interval=-0.5, timeout=1.0
)
Loading