Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix interference between test_tracetools and ros2lifecycle tests #96

Merged
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
30 changes: 14 additions & 16 deletions test_tracetools/test/test_lifecycle_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(self, *args) -> None:
],
package='test_tracetools',
nodes=['test_lifecycle_node', 'test_lifecycle_client'],
namespace='/test_tracetools',
)

def test_all(self):
Expand All @@ -46,6 +47,11 @@ def test_all(self):
'test_lifecycle_node',
rcl_node_init_events,
)
lifecycle_node_matches = self.get_events_with_field_value(
'namespace',
'/test_tracetools',
lifecycle_node_matches,
)
self.assertNumEventsEqual(lifecycle_node_matches, 1)
lifecycle_node_handle = self.get_field(lifecycle_node_matches[0], 'node_handle')

Expand All @@ -69,7 +75,6 @@ def test_all(self):

# This list of states corresponds to the states that the test_lifecycle_node goes through
# following test_lifecycle_client's requests
# We do not expect any other lifecycle node
expected_lifecycle_states = [
'unconfigured',
'configuring',
Expand All @@ -90,29 +95,22 @@ def test_all(self):
(expected_lifecycle_states[i], expected_lifecycle_states[i + 1])
for i in range(len(expected_lifecycle_states) - 1)
]
# Check transitions
rcl_lifecycle_transition_events = self.get_events_with_name(
tp.rcl_lifecycle_transition)
# Check transitions for our state machine
rcl_lifecycle_transition_events = self.get_events_with_name(tp.rcl_lifecycle_transition)
transition_events = self.get_events_with_field_value(
'state_machine',
state_machine_handle,
rcl_lifecycle_transition_events,
)
lifecycle_state_transitions = [
(self.get_field(event, 'start_label'), self.get_field(event, 'goal_label'))
for event in rcl_lifecycle_transition_events
for event in transition_events
]
self.assertListEqual(
expected_lifecycle_state_transitions,
lifecycle_state_transitions,
'transitions not valid',
)
# Make sure all state machine handle values match the one from the init event
self.assertTrue(
all(
self.get_field(event, 'state_machine') == state_machine_handle
for event in rcl_lifecycle_transition_events
),
(
f"state machine handles do not all match '{state_machine_handle}': "
f'{rcl_lifecycle_transition_events}'
),
)


if __name__ == '__main__':
Expand Down
3 changes: 3 additions & 0 deletions tracetools_test/tracetools_test/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def __init__(
base_path: str = '/tmp',
events_kernel: List[str] = [],
additional_actions: Optional[List[Action]] = None,
namespace: Optional[str] = None,
) -> None:
"""Create a TraceTestCase."""
super().__init__(methodName=args[0])
Expand All @@ -73,6 +74,7 @@ def __init__(
self._package = package
self._nodes = nodes
self._additional_actions = additional_actions or []
self._namespace = namespace

def setUp(self):
# Get timestamp before trace (ns)
Expand All @@ -85,6 +87,7 @@ def setUp(self):
self._events_kernel,
self._package,
self._nodes,
self._namespace,
self._additional_actions,
)

Expand Down
4 changes: 4 additions & 0 deletions tracetools_test/tracetools_test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import os
import shutil
from typing import List
from typing import Optional
from typing import Tuple

from launch import Action
Expand All @@ -36,6 +37,7 @@ def run_and_trace(
kernel_events: List[str],
package_name: str,
node_names: List[str],
namespace: Optional[str],
additional_actions: List[Action],
) -> Tuple[int, str]:
"""
Expand All @@ -47,6 +49,7 @@ def run_and_trace(
:param kernel_events: the list of kernel events to enable
:param package_name: the name of the package to use
:param node_names: the names of the nodes to execute
:param namespace: the ROS namespace for the node(s)
:param additional_actions: the list of additional actions to append
:return: exit code, full generated path
"""
Expand All @@ -69,6 +72,7 @@ def run_and_trace(
n = Node(
package=package_name,
executable=node_name,
namespace=namespace,
output='screen',
)
launch_actions.append(n)
Expand Down
Loading