Skip to content
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
24 changes: 14 additions & 10 deletions rclcpp/test/rclcpp/test_generic_pubsub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,6 @@ TEST_F(RclcppGenericNodeFixture, disable_enable_subscription_callbacks)

TEST_F(RclcppGenericNodeFixture, disable_enable_subscription_event_callbacks)
{
if (std::string(rmw_get_implementation_identifier()).find("rmw_zenoh_cpp") == 0) {
GTEST_SKIP() << "rmw_zenoh doesn't support deadline and liveliness events";
}
const std::string topic_name = "test_event_callbacks_topic";
const std::string type = "test_msgs/msg/Strings";
const auto qos = rclcpp::QoS(10U).deadline(100ms);
Expand All @@ -409,6 +406,13 @@ TEST_F(RclcppGenericNodeFixture, disable_enable_subscription_event_callbacks)
node_->create_generic_subscription(topic_name, type, qos, do_nothing, sub_options);

const auto & event_handlers = subscription->get_event_handlers();
// rclcpp creates no handler (and warns) for an event type the RMW doesn't support.
const int deadline_step =
event_handlers.count(RCL_SUBSCRIPTION_REQUESTED_DEADLINE_MISSED) ? 1 : 0;
const int liveliness_step = event_handlers.count(RCL_SUBSCRIPTION_LIVELINESS_CHANGED) ? 1 : 0;
if (deadline_step + liveliness_step == 0) {
GTEST_SKIP() << "the RMW supports neither deadline nor liveliness events";
}

// Initially, both callbacks counters should be zero
EXPECT_EQ(deadline_callback_count, 0);
Expand All @@ -422,9 +426,9 @@ TEST_F(RclcppGenericNodeFixture, disable_enable_subscription_event_callbacks)
EXPECT_NO_THROW(handler->disable());
}
}
// Expect both callbacks to have been called once since they should be enabled by default
EXPECT_EQ(deadline_callback_count, 1);
EXPECT_EQ(liveliness_callback_count, 1);
// Expect each handler that exists to have called back once, since handlers start enabled
EXPECT_EQ(deadline_callback_count, deadline_step);
EXPECT_EQ(liveliness_callback_count, liveliness_step);

// Execute events one more time and enable all event handlers
for (const auto & [event_type, handler] : event_handlers) {
Expand All @@ -435,8 +439,8 @@ TEST_F(RclcppGenericNodeFixture, disable_enable_subscription_event_callbacks)
}
}
// Expect no change since they were disabled
EXPECT_EQ(deadline_callback_count, 1);
EXPECT_EQ(liveliness_callback_count, 1);
EXPECT_EQ(deadline_callback_count, deadline_step);
EXPECT_EQ(liveliness_callback_count, liveliness_step);

// Execute events one more time
for (const auto & [event_type, handler] : event_handlers) {
Expand All @@ -445,6 +449,6 @@ TEST_F(RclcppGenericNodeFixture, disable_enable_subscription_event_callbacks)
handler->execute(data);
}
}
EXPECT_EQ(deadline_callback_count, 2);
EXPECT_EQ(liveliness_callback_count, 2);
EXPECT_EQ(deadline_callback_count, 2 * deadline_step);
EXPECT_EQ(liveliness_callback_count, 2 * liveliness_step);
}
21 changes: 14 additions & 7 deletions rclcpp/test/rclcpp/test_subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,13 @@ TEST_F(TestSubscription, disable_enable_event_callbacks)
"test_event_callbacks_topic", qos, do_nothing, subscription_options);

const auto & event_handlers = subscription->get_event_handlers();
// rclcpp creates no handler (and warns) for an event type the RMW doesn't support.
const int deadline_step =
event_handlers.count(RCL_SUBSCRIPTION_REQUESTED_DEADLINE_MISSED) ? 1 : 0;
const int liveliness_step = event_handlers.count(RCL_SUBSCRIPTION_LIVELINESS_CHANGED) ? 1 : 0;
if (deadline_step + liveliness_step == 0) {
GTEST_SKIP() << "the RMW supports neither deadline nor liveliness events";
}

// Initially, both callbacks counters should be zero
EXPECT_EQ(deadline_callback_count, 0);
Expand All @@ -843,9 +850,9 @@ TEST_F(TestSubscription, disable_enable_event_callbacks)
EXPECT_NO_THROW(handler->disable());
}
}
// Expect both callbacks to have been called once since they should be enabled by default
EXPECT_EQ(deadline_callback_count, 1);
EXPECT_EQ(liveliness_callback_count, 1);
// Expect each handler that exists to have called back once, since handlers start enabled
EXPECT_EQ(deadline_callback_count, deadline_step);
EXPECT_EQ(liveliness_callback_count, liveliness_step);

// Execute events one more time and enable all event handlers
for (const auto & [event_type, handler] : event_handlers) {
Expand All @@ -856,8 +863,8 @@ TEST_F(TestSubscription, disable_enable_event_callbacks)
}
}
// Expect no change since they were disabled
EXPECT_EQ(deadline_callback_count, 1);
EXPECT_EQ(liveliness_callback_count, 1);
EXPECT_EQ(deadline_callback_count, deadline_step);
EXPECT_EQ(liveliness_callback_count, liveliness_step);

// Execute events one more time
for (const auto & [event_type, handler] : event_handlers) {
Expand All @@ -866,6 +873,6 @@ TEST_F(TestSubscription, disable_enable_event_callbacks)
handler->execute(data);
}
}
EXPECT_EQ(deadline_callback_count, 2);
EXPECT_EQ(liveliness_callback_count, 2);
EXPECT_EQ(deadline_callback_count, 2 * deadline_step);
EXPECT_EQ(liveliness_callback_count, 2 * liveliness_step);
}
Loading