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

Increase coverage of WaitSetTemplate #1368

Merged
merged 2 commits into from
Oct 1, 2020
Merged
Changes from 1 commit
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
62 changes: 62 additions & 0 deletions rclcpp/test/rclcpp/test_wait_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,68 @@ TEST_F(TestWaitSet, add_guard_condition_to_two_different_wait_set) {
}
}


/*
* Testing adding each entity and waiting, and removing each entity and waiting
*/
TEST_F(TestWaitSet, add_remove_wait) {
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the extra scope block needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed scope

rclcpp::WaitSet wait_set;
auto node = std::make_shared<rclcpp::Node>("add_remove_wait");

auto guard_condition = std::make_shared<rclcpp::GuardCondition>();
guard_condition->trigger();

// For coverage reasons, this subscription should have event handlers
rclcpp::SubscriptionOptions subscription_options;
subscription_options.event_callbacks.deadline_callback = [](auto) {};
subscription_options.event_callbacks.liveliness_callback = [](auto) {};
auto do_nothing = [](const std::shared_ptr<test_msgs::msg::BasicTypes>) {};
auto sub =
node->create_subscription<test_msgs::msg::BasicTypes>(
"~/test", 1, do_nothing, subscription_options);

auto timer = node->create_wall_timer(std::chrono::milliseconds(1), []() {});

auto client = node->create_client<rcl_interfaces::srv::ListParameters>("~/test");

auto srv_do_nothing = [](
const std::shared_ptr<rcl_interfaces::srv::ListParameters::Request>,
std::shared_ptr<rcl_interfaces::srv::ListParameters::Response>) {};
auto service =
node->create_service<rcl_interfaces::srv::ListParameters>("~/test", srv_do_nothing);

rclcpp::PublisherOptions publisher_options;
publisher_options.event_callbacks.deadline_callback =
[](rclcpp::QOSDeadlineOfferedInfo &) {};
auto pub = node->create_publisher<test_msgs::msg::BasicTypes>(
"~/test", 1, publisher_options);
auto qos_event = pub->get_event_handlers()[0];

// Subscription mask is required here for coverage.
wait_set.add_subscription(sub, {true, true, true});
wait_set.add_guard_condition(guard_condition);
wait_set.add_timer(timer);
wait_set.add_client(client);
wait_set.add_service(service);
wait_set.add_waitable(qos_event, pub);

// At least timer or guard_condition should trigger
EXPECT_EQ(
rclcpp::WaitResultKind::Ready, wait_set.wait(std::chrono::seconds(1)).kind());

wait_set.remove_subscription(sub, {true, true, true});
wait_set.remove_guard_condition(guard_condition);
wait_set.remove_timer(timer);
wait_set.remove_client(client);
wait_set.remove_service(service);
wait_set.remove_waitable(qos_event);

EXPECT_EQ(
rclcpp::WaitResultKind::Empty, wait_set.wait(std::chrono::seconds(1)).kind());
}
}

/*
* Get wait_set from result.
*/
Expand Down