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

add use_global_arguments for node options of component nodes #1776

Merged
merged 2 commits into from
Jan 19, 2022
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
12 changes: 12 additions & 0 deletions rclcpp_components/src/component_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ ComponentManager::create_node_options(const std::shared_ptr<LoadNode::Request> r
"Extra component argument 'use_intra_process_comms' must be a boolean");
}
options.use_intra_process_comms(extra_argument.get_value<bool>());
} else if (extra_argument.get_name() == "forward_global_arguments") {
if (extra_argument.get_type() != rclcpp::ParameterType::PARAMETER_BOOL) {
throw ComponentManagerException(
"Extra component argument 'forward_global_arguments' must be a boolean");
}
options.use_global_arguments(extra_argument.get_value<bool>());
if (extra_argument.get_value<bool>()) {
RCLCPP_WARN(
get_logger(), "forward_global_arguments is true by default in nodes, but is not "
"recommended in a component manager. If true, this will cause this node's behavior "
"to be influenced by global arguments, not only those targeted at this node.");
}
}
}

Expand Down
55 changes: 51 additions & 4 deletions rclcpp_components/test/test_component_manager_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,49 @@ TEST_F(TestComponentManager, components_api)
EXPECT_EQ(result->unique_id, 0u);
}

{
// forward_global_arguments
auto request = std::make_shared<composition_interfaces::srv::LoadNode::Request>();
request->package_name = "rclcpp_components";
request->plugin_name = "test_rclcpp_components::TestComponentFoo";
request->node_name = "test_component_global_arguments";
rclcpp::Parameter forward_global_arguments("forward_global_arguments",
rclcpp::ParameterValue(true));
request->extra_arguments.push_back(forward_global_arguments.to_parameter_msg());

auto future = composition_client->async_send_request(request);
auto ret = exec->spin_until_future_complete(future, 5s); // Wait for the result.
auto result = future.get();
EXPECT_EQ(ret, rclcpp::FutureReturnCode::SUCCESS);
EXPECT_EQ(result->success, true);
EXPECT_EQ(result->error_message, "");
EXPECT_EQ(result->full_node_name, "/test_component_global_arguments");
EXPECT_EQ(result->unique_id, 7u);
Copy link
Contributor

Choose a reason for hiding this comment

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

@gezp nit: this tests that the manager did not fail but not that it did anything about use_global_arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, use_global_arguments is set true in NodeOption , but this component didn't use any global arguments, i don't know how to test for this.

}

{
// forward_global_arguments is not a bool type parameter
auto request = std::make_shared<composition_interfaces::srv::LoadNode::Request>();
request->package_name = "rclcpp_components";
request->plugin_name = "test_rclcpp_components::TestComponentFoo";
request->node_name = "test_component_global_arguments_str";

rclcpp::Parameter forward_global_arguments("forward_global_arguments",
rclcpp::ParameterValue("hello"));
request->extra_arguments.push_back(forward_global_arguments.to_parameter_msg());

auto future = composition_client->async_send_request(request);
auto ret = exec->spin_until_future_complete(future, 5s); // Wait for the result.
auto result = future.get();
EXPECT_EQ(ret, rclcpp::FutureReturnCode::SUCCESS);
EXPECT_EQ(result->success, false);
EXPECT_EQ(
result->error_message,
"Extra component argument 'forward_global_arguments' must be a boolean");
EXPECT_EQ(result->full_node_name, "");
EXPECT_EQ(result->unique_id, 0u);
}

auto node_names = node->get_node_names();

auto find_in_nodes = [node_names](std::string name) {
Expand Down Expand Up @@ -239,20 +282,22 @@ TEST_F(TestComponentManager, components_api)
auto result_node_names = result->full_node_names;
auto result_unique_ids = result->unique_ids;

EXPECT_EQ(result_node_names.size(), 6u);
EXPECT_EQ(result_node_names.size(), 7u);
EXPECT_EQ(result_node_names[0], "/test_component_foo");
EXPECT_EQ(result_node_names[1], "/test_component_bar");
EXPECT_EQ(result_node_names[2], "/test_component_baz");
EXPECT_EQ(result_node_names[3], "/ns/test_component_bing");
EXPECT_EQ(result_node_names[4], "/test_component_remap");
EXPECT_EQ(result_node_names[5], "/test_component_intra_process");
EXPECT_EQ(result_unique_ids.size(), 6u);
EXPECT_EQ(result_node_names[6], "/test_component_global_arguments");
EXPECT_EQ(result_unique_ids.size(), 7u);
EXPECT_EQ(result_unique_ids[0], 1u);
EXPECT_EQ(result_unique_ids[1], 2u);
EXPECT_EQ(result_unique_ids[2], 3u);
EXPECT_EQ(result_unique_ids[3], 4u);
EXPECT_EQ(result_unique_ids[4], 5u);
EXPECT_EQ(result_unique_ids[5], 6u);
EXPECT_EQ(result_unique_ids[6], 7u);
}
}

Expand Down Expand Up @@ -306,18 +351,20 @@ TEST_F(TestComponentManager, components_api)
auto result_node_names = result->full_node_names;
auto result_unique_ids = result->unique_ids;

EXPECT_EQ(result_node_names.size(), 5u);
EXPECT_EQ(result_node_names.size(), 6u);
EXPECT_EQ(result_node_names[0], "/test_component_bar");
EXPECT_EQ(result_node_names[1], "/test_component_baz");
EXPECT_EQ(result_node_names[2], "/ns/test_component_bing");
EXPECT_EQ(result_node_names[3], "/test_component_remap");
EXPECT_EQ(result_node_names[4], "/test_component_intra_process");
EXPECT_EQ(result_unique_ids.size(), 5u);
EXPECT_EQ(result_node_names[5], "/test_component_global_arguments");
EXPECT_EQ(result_unique_ids.size(), 6u);
EXPECT_EQ(result_unique_ids[0], 2u);
EXPECT_EQ(result_unique_ids[1], 3u);
EXPECT_EQ(result_unique_ids[2], 4u);
EXPECT_EQ(result_unique_ids[3], 5u);
EXPECT_EQ(result_unique_ids[4], 6u);
EXPECT_EQ(result_unique_ids[5], 7u);
}
}
}