Skip to content

Commit

Permalink
Revert "removed coltroller test for testing timeout"
Browse files Browse the repository at this point in the history
This reverts commit 50c90e5.
  • Loading branch information
delihus committed Jan 9, 2024
1 parent bd0d026 commit 98f3d48
Show file tree
Hide file tree
Showing 8 changed files with 639 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/industrial_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
ros_industrial_ci:
name: ROS Industrial CI
runs-on: ubuntu-22.04
timeout-minutes: 20
timeout-minutes: 60
needs:
- black
- spellcheck
Expand Down
101 changes: 101 additions & 0 deletions rosbot_controller/test/test_diff_drive_controllers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Copyright 2021 Open Source Robotics Foundation, Inc.
# Copyright 2023 Intel Corporation. All Rights Reserved.
# Copyright 2023 Husarion
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import launch_pytest
import pytest
import rclpy

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription
from launch.substitutions import PathJoinSubstitution
from launch.launch_description_sources import PythonLaunchDescriptionSource
from test_utils import ControllersTestNode


@launch_pytest.fixture
def generate_test_description():
rosbot_controller = get_package_share_directory("rosbot_controller")
bringup_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
PathJoinSubstitution(
[
rosbot_controller,
"launch",
"controller.launch.py",
]
)
),
launch_arguments={
"use_sim": "False",
"mecanum": "False",
"use_gpu": "False",
}.items(),
)

return LaunchDescription([bringup_launch])


@pytest.mark.launch(fixture=generate_test_description)
def test_controllers_startup_fail():
rclpy.init()
try:
node = ControllersTestNode("test_controllers_bringup")
node.create_test_subscribers_and_publishers()

node.start_node_thread()
msgs_received_flag = node.joint_state_msg_event.wait(timeout=10.0)
assert not msgs_received_flag, (
"Received JointStates message that should not have appeared. Check whether other"
" robots are connected to your network.!"
)
msgs_received_flag = node.odom_msg_event.wait(timeout=10.0)
assert not msgs_received_flag, (
"Received Odom message that should not have appeared. Check whether other robots are"
" connected to your network.!"
)
msgs_received_flag = node.imu_msg_event.wait(timeout=10.0)
assert not msgs_received_flag, (
"Received Imu message that should not have appeared. Check whether other robots are"
" connected to your network.!"
)
finally:
rclpy.shutdown()


@pytest.mark.launch(fixture=generate_test_description)
def test_controllers_startup_success():
rclpy.init()
try:
node = ControllersTestNode("test_controllers_bringup")
node.create_test_subscribers_and_publishers()
node.start_publishing_fake_hardware()

node.start_node_thread()
msgs_received_flag = node.joint_state_msg_event.wait(timeout=10.0)
assert (
msgs_received_flag
), "Expected JointStates message but it was not received. Check joint_state_broadcaster!"
msgs_received_flag = node.odom_msg_event.wait(timeout=10.0)
assert (
msgs_received_flag
), "Expected Odom message but it was not received. Check rosbot_base_controller!"
msgs_received_flag = node.imu_msg_event.wait(timeout=10.0)
assert (
msgs_received_flag
), "Expected Imu message but it was not received. Check imu_broadcaster!"
finally:
rclpy.shutdown()
101 changes: 101 additions & 0 deletions rosbot_controller/test/test_mecanum_controllers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Copyright 2021 Open Source Robotics Foundation, Inc.
# Copyright 2023 Intel Corporation. All Rights Reserved.
# Copyright 2023 Husarion
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import launch_pytest
import pytest
import rclpy

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription
from launch.substitutions import PathJoinSubstitution
from launch.launch_description_sources import PythonLaunchDescriptionSource
from test_utils import ControllersTestNode


@launch_pytest.fixture
def generate_test_description():
rosbot_controller = get_package_share_directory("rosbot_controller")
bringup_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
PathJoinSubstitution(
[
rosbot_controller,
"launch",
"controller.launch.py",
]
)
),
launch_arguments={
"use_sim": "False",
"mecanum": "True",
"use_gpu": "False",
}.items(),
)

return LaunchDescription([bringup_launch])


@pytest.mark.launch(fixture=generate_test_description)
def test_controllers_startup_fail():
rclpy.init()
try:
node = ControllersTestNode("test_controllers_bringup")
node.create_test_subscribers_and_publishers()

node.start_node_thread()
msgs_received_flag = node.joint_state_msg_event.wait(timeout=10.0)
assert not msgs_received_flag, (
"Received JointStates message that should not have appeared. Check whether other"
" robots are connected to your network.!"
)
msgs_received_flag = node.odom_msg_event.wait(timeout=10.0)
assert not msgs_received_flag, (
"Received Odom message that should not have appeared. Check whether other robots are"
" connected to your network.!"
)
msgs_received_flag = node.imu_msg_event.wait(timeout=10.0)
assert not msgs_received_flag, (
"Received Imu message that should not have appeared. Check whether other robots are"
" connected to your network.!"
)
finally:
rclpy.shutdown()


@pytest.mark.launch(fixture=generate_test_description)
def test_controllers_startup_success():
rclpy.init()
try:
node = ControllersTestNode("test_controllers_bringup")
node.create_test_subscribers_and_publishers()
node.start_publishing_fake_hardware()

node.start_node_thread()
msgs_received_flag = node.joint_state_msg_event.wait(timeout=10.0)
assert (
msgs_received_flag
), "Expected JointStates message but it was not received. Check joint_state_broadcaster!"
msgs_received_flag = node.odom_msg_event.wait(timeout=10.0)
assert (
msgs_received_flag
), "Expected Odom message but it was not received. Check rosbot_base_controller!"
msgs_received_flag = node.imu_msg_event.wait(timeout=10.0)
assert (
msgs_received_flag
), "Expected Imu message but it was not received. Check imu_broadcaster!"
finally:
rclpy.shutdown()
84 changes: 84 additions & 0 deletions rosbot_controller/test/test_multirobot_controllers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Copyright 2021 Open Source Robotics Foundation, Inc.
# Copyright 2023 Intel Corporation. All Rights Reserved.
# Copyright 2023 Husarion
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import launch_pytest
import pytest
import rclpy

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription
from launch.substitutions import PathJoinSubstitution
from launch.launch_description_sources import PythonLaunchDescriptionSource
from test_utils import ControllersTestNode

robot_names = ["rosbot1", "rosbot2", "rosbot3", "rosbot4"]


@launch_pytest.fixture
def generate_test_description():
rosbot_controller = get_package_share_directory("rosbot_controller")
actions = []
for i in range(len(robot_names)):
controller_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
PathJoinSubstitution(
[
rosbot_controller,
"launch",
"controller.launch.py",
]
)
),
launch_arguments={
"use_sim": "False",
"mecanum": "True",
"use_gpu": "False",
"namespace": robot_names[i],
}.items(),
)

actions.append(controller_launch)

return LaunchDescription(actions)


@pytest.mark.launch(fixture=generate_test_description)
def test_multirobot_controllers_startup_success():
for robot_name in robot_names:
rclpy.init()
try:
node = ControllersTestNode(f"test_{robot_name}_controllers", namespace=robot_name)
node.create_test_subscribers_and_publishers()
node.start_publishing_fake_hardware()

node.start_node_thread()
msgs_received_flag = node.joint_state_msg_event.wait(timeout=10.0)
assert msgs_received_flag, (
f"Expected JointStates message but it was not received. Check {robot_name}/"
"joint_state_broadcaster!"
)
msgs_received_flag = node.odom_msg_event.wait(timeout=10.0)
assert msgs_received_flag, (
f"Expected Odom message but it was not received. Check {robot_name}/"
"rosbot_base_controller!"
)
msgs_received_flag = node.imu_msg_event.wait(timeout=10.0)
assert (
msgs_received_flag
), f"Expected Imu message but it was not received. Check {robot_name}/imu_broadcaster!"
finally:
rclpy.shutdown()
Loading

0 comments on commit 98f3d48

Please sign in to comment.