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

Remove fastrtps customization on tests #895

Merged
Merged
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
141 changes: 56 additions & 85 deletions rclpy/test/test_qos_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@
from rclpy.qos_event import QoSRequestedIncompatibleQoSInfo
from rclpy.qos_event import QoSSubscriptionEventType
from rclpy.qos_event import SubscriptionEventCallbacks
from rclpy.qos_event import UnsupportedEventTypeError
from rclpy.task import Future
from rclpy.utilities import get_rmw_implementation_identifier

from test_msgs.msg import Empty as EmptyMsg


class TestQoSEvent(unittest.TestCase):
is_fastrtps = False
topic_name = 'test_topic'

def setUp(self):
Expand All @@ -48,7 +45,6 @@ def setUp(self):
self.node = rclpy.create_node('TestQoSEvent',
namespace='/rclpy/test',
context=self.context)
self.is_fastrtps = 'rmw_fastrtps' in get_rmw_implementation_identifier()

def tearDown(self):
# These tests create a bunch of events by hand instead of using Node APIs,
Expand All @@ -64,7 +60,7 @@ def test_publisher_constructor(self):
liveliness_callback = Mock()
deadline_callback = Mock()
incompatible_qos_callback = Mock()
expected_num_event_handlers = 0 if self.is_fastrtps else 1
expected_num_event_handlers = 1

# No arg
publisher = self.node.create_publisher(EmptyMsg, self.topic_name, 10)
Expand Down Expand Up @@ -95,21 +91,18 @@ def test_publisher_constructor(self):

# Arg with three callbacks
callbacks.incompatible_qos = incompatible_qos_callback
try:
publisher = self.node.create_publisher(
EmptyMsg, self.topic_name, 10, event_callbacks=callbacks)
self.assertEqual(len(publisher.event_handlers), 3)
self.node.destroy_publisher(publisher)
except UnsupportedEventTypeError:
self.assertTrue(self.is_fastrtps)
publisher = self.node.create_publisher(
EmptyMsg, self.topic_name, 10, event_callbacks=callbacks)
self.assertEqual(len(publisher.event_handlers), 3)
self.node.destroy_publisher(publisher)

def test_subscription_constructor(self):
callbacks = SubscriptionEventCallbacks()
liveliness_callback = Mock()
deadline_callback = Mock()
message_callback = Mock()
incompatible_qos_callback = Mock()
expected_num_event_handlers = 0 if self.is_fastrtps else 1
expected_num_event_handlers = 1

# No arg
subscription = self.node.create_subscription(
Expand Down Expand Up @@ -141,13 +134,10 @@ def test_subscription_constructor(self):

# Arg with three callbacks
callbacks.incompatible_qos = incompatible_qos_callback
try:
subscription = self.node.create_subscription(
EmptyMsg, self.topic_name, message_callback, 10, event_callbacks=callbacks)
self.assertEqual(len(subscription.event_handlers), 3)
self.node.destroy_subscription(subscription)
except UnsupportedEventTypeError:
self.assertTrue(self.is_fastrtps)
subscription = self.node.create_subscription(
EmptyMsg, self.topic_name, message_callback, 10, event_callbacks=callbacks)
self.assertEqual(len(subscription.event_handlers), 3)
self.node.destroy_subscription(subscription)

def test_default_incompatible_qos_callbacks(self):
original_logger = rclpy.logging._root_logger
Expand Down Expand Up @@ -187,17 +177,16 @@ def warn(self, message, once=False):
executor = rclpy.executors.SingleThreadedExecutor(context=self.context)
rclpy.spin_until_future_complete(self.node, log_msgs_future, executor, 10.0)

if not self.is_fastrtps:
self.assertEqual(
pub_log_msg,
"New subscription discovered on topic '{}', requesting incompatible QoS. "
'No messages will be sent to it. '
'Last incompatible policy: DURABILITY'.format(self.topic_name))
self.assertEqual(
sub_log_msg,
"New publisher discovered on topic '{}', offering incompatible QoS. "
'No messages will be received from it. '
'Last incompatible policy: DURABILITY'.format(self.topic_name))
self.assertEqual(
pub_log_msg,
"New subscription discovered on topic '{}', requesting incompatible QoS. "
'No messages will be sent to it. '
'Last incompatible policy: DURABILITY'.format(self.topic_name))
self.assertEqual(
sub_log_msg,
"New publisher discovered on topic '{}', offering incompatible QoS. "
'No messages will be received from it. '
'Last incompatible policy: DURABILITY'.format(self.topic_name))

rclpy.logging._root_logger = original_logger

Expand All @@ -217,11 +206,8 @@ def test_publisher_event_create_destroy(self):
publisher, QoSPublisherEventType.RCL_PUBLISHER_OFFERED_DEADLINE_MISSED)
self._do_create_destroy(
publisher, QoSPublisherEventType.RCL_PUBLISHER_LIVELINESS_LOST)
try:
self._do_create_destroy(
publisher, QoSPublisherEventType.RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS)
except UnsupportedEventTypeError:
self.assertTrue(self.is_fastrtps)
self._do_create_destroy(
publisher, QoSPublisherEventType.RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS)
self.node.destroy_publisher(publisher)

def test_subscription_event_create_destroy(self):
Expand All @@ -232,11 +218,8 @@ def test_subscription_event_create_destroy(self):
subscription, QoSSubscriptionEventType.RCL_SUBSCRIPTION_LIVELINESS_CHANGED)
self._do_create_destroy(
subscription, QoSSubscriptionEventType.RCL_SUBSCRIPTION_REQUESTED_DEADLINE_MISSED)
try:
self._do_create_destroy(
subscription, QoSSubscriptionEventType.RCL_SUBSCRIPTION_REQUESTED_INCOMPATIBLE_QOS)
except UnsupportedEventTypeError:
self.assertTrue(self.is_fastrtps)
self._do_create_destroy(
subscription, QoSSubscriptionEventType.RCL_SUBSCRIPTION_REQUESTED_INCOMPATIBLE_QOS)
self.node.destroy_subscription(subscription)

def test_call_publisher_rclpy_event_apis(self):
Expand All @@ -259,24 +242,19 @@ def test_call_publisher_rclpy_event_apis(self):
liveliness_event_handle)
self.assertIsNotNone(liveliness_event_index)

try:
incompatible_qos_event_handle = self._create_event_handle(
publisher, QoSPublisherEventType.RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS)
with incompatible_qos_event_handle:
incompatible_qos_event_index = wait_set.add_event(
incompatible_qos_event_handle)
self.assertIsNotNone(incompatible_qos_event_index)
except UnsupportedEventTypeError:
self.assertTrue(self.is_fastrtps)
incompatible_qos_event_handle = self._create_event_handle(
publisher, QoSPublisherEventType.RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS)
with incompatible_qos_event_handle:
incompatible_qos_event_index = wait_set.add_event(
incompatible_qos_event_handle)
self.assertIsNotNone(incompatible_qos_event_index)

# We live in our own namespace and have created no other participants, so
# there can't be any of these events.
wait_set.wait(0)
self.assertFalse(wait_set.is_ready('event', deadline_event_index))
self.assertFalse(wait_set.is_ready('event', liveliness_event_index))
if not self.is_fastrtps:
self.assertFalse(wait_set.is_ready(
'event', incompatible_qos_event_index))
self.assertFalse(wait_set.is_ready('event', incompatible_qos_event_index))

# Calling take data even though not ready should provide me an empty initialized message
# Tests data conversion utilities in C side
Expand All @@ -298,16 +276,15 @@ def test_call_publisher_rclpy_event_apis(self):
except NotImplementedError:
pass

if not self.is_fastrtps:
try:
with incompatible_qos_event_handle:
event_data = incompatible_qos_event_handle.take_event()
self.assertIsInstance(event_data, QoSOfferedIncompatibleQoSInfo)
self.assertEqual(event_data.total_count, 0)
self.assertEqual(event_data.total_count_change, 0)
self.assertEqual(event_data.last_policy_kind, QoSPolicyKind.INVALID)
except NotImplementedError:
pass
try:
with incompatible_qos_event_handle:
event_data = incompatible_qos_event_handle.take_event()
self.assertIsInstance(event_data, QoSOfferedIncompatibleQoSInfo)
self.assertEqual(event_data.total_count, 0)
self.assertEqual(event_data.total_count_change, 0)
self.assertEqual(event_data.last_policy_kind, QoSPolicyKind.INVALID)
except NotImplementedError:
pass

self.node.destroy_publisher(publisher)

Expand All @@ -330,24 +307,19 @@ def test_call_subscription_rclpy_event_apis(self):
liveliness_event_index = wait_set.add_event(liveliness_event_handle)
self.assertIsNotNone(liveliness_event_index)

try:
incompatible_qos_event_handle = self._create_event_handle(
subscription, QoSSubscriptionEventType.RCL_SUBSCRIPTION_REQUESTED_INCOMPATIBLE_QOS)
with incompatible_qos_event_handle:
incompatible_qos_event_index = wait_set.add_event(
incompatible_qos_event_handle)
self.assertIsNotNone(incompatible_qos_event_index)
except UnsupportedEventTypeError:
self.assertTrue(self.is_fastrtps)
incompatible_qos_event_handle = self._create_event_handle(
subscription, QoSSubscriptionEventType.RCL_SUBSCRIPTION_REQUESTED_INCOMPATIBLE_QOS)
with incompatible_qos_event_handle:
incompatible_qos_event_index = wait_set.add_event(
incompatible_qos_event_handle)
self.assertIsNotNone(incompatible_qos_event_index)

# We live in our own namespace and have created no other participants, so
# there can't be any of these events.
wait_set.wait(0)
self.assertFalse(wait_set.is_ready('event', deadline_event_index))
self.assertFalse(wait_set.is_ready('event', liveliness_event_index))
if not self.is_fastrtps:
self.assertFalse(wait_set.is_ready(
'event', incompatible_qos_event_index))
self.assertFalse(wait_set.is_ready('event', incompatible_qos_event_index))

# Calling take data even though not ready should provide me an empty initialized message
# Tests data conversion utilities in C side
Expand All @@ -371,15 +343,14 @@ def test_call_subscription_rclpy_event_apis(self):
except NotImplementedError:
pass

if not self.is_fastrtps:
try:
with incompatible_qos_event_handle:
event_data = incompatible_qos_event_handle.take_event()
self.assertIsInstance(event_data, QoSRequestedIncompatibleQoSInfo)
self.assertEqual(event_data.total_count, 0)
self.assertEqual(event_data.total_count_change, 0)
self.assertEqual(event_data.last_policy_kind, QoSPolicyKind.INVALID)
except NotImplementedError:
pass
try:
with incompatible_qos_event_handle:
event_data = incompatible_qos_event_handle.take_event()
self.assertIsInstance(event_data, QoSRequestedIncompatibleQoSInfo)
self.assertEqual(event_data.total_count, 0)
self.assertEqual(event_data.total_count_change, 0)
self.assertEqual(event_data.last_policy_kind, QoSPolicyKind.INVALID)
except NotImplementedError:
pass

self.node.destroy_subscription(subscription)