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

update test to catch repeated service callbacks #34

Merged
merged 1 commit into from
Aug 27, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 15 additions & 4 deletions test_communication/test/test_replier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ void reply(
rclcpp::Node::SharedPtr node,
const std::string & service_type,
const std::vector<
std::pair<typename T::Request::SharedPtr, typename T::Response::SharedPtr>> & expected_services
std::pair<typename T::Request::SharedPtr, typename T::Response::SharedPtr>> & expected_services,
std::vector<bool> & received_messages
)
{
received_messages.assign(expected_services.size(), false);

// *INDENT-OFF* (prevent uncrustify from making unecessary indents here)
auto callback =
[&expected_services](
[&expected_services, &received_messages](
const typename T::Request::SharedPtr received_request,
typename T::Response::SharedPtr response) -> void
{
Expand All @@ -44,6 +47,12 @@ void reply(
expected_services.size() << std::endl;
*response = *expected_service.second;
known_request = true;
if (received_messages[index]) {
fprintf(stderr, "received the same request multiple times\n");
rclcpp::shutdown();
throw std::runtime_error("received the same request multiple times");
}
received_messages[index] = true;
break;
}
++index;
Expand Down Expand Up @@ -75,12 +84,14 @@ int main(int argc, char ** argv)
auto services_empty = get_services_empty();
auto services_primitives = get_services_primitives();

std::vector<bool> received_messages;

if (service == "empty") {
reply<test_communication::srv::Empty>(
node, service, services_empty);
node, service, services_empty, received_messages);
} else if (service == "primitives") {
reply<test_communication::srv::Primitives>(
node, service, services_primitives);
node, service, services_primitives, received_messages);
} else {
fprintf(stderr, "Unknown service argument '%s'\n", service.c_str());
return 1;
Expand Down