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

Regression test for set_parameters with bad callback reference #253

Merged
merged 3 commits into from
Dec 4, 2017

Conversation

dhood
Copy link
Member

@dhood dhood commented Dec 3, 2017

Connects to ros2/rclcpp#414
Regression test for ros2/rclcpp#414

Without ros2/rclcpp#414, the test will crash (I'm getting C++ exception with description "std::bad_alloc" thrown in the test body. but in https://github.com/ros2/demos/pull/203/files#diff-a5a151889abb3214250ba9db05358e4bR92 it would segfault).

CI including ros2/rclcpp#414

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS skipped because queue is busy
  • Windows Build Status

@dhood dhood added the in review Waiting for review (Kanban column) label Dec 3, 2017
@dhood dhood self-assigned this Dec 3, 2017
node->parameters_client_ =
std::make_shared<rclcpp::parameter_client::AsyncParametersClient>(node);
if (!node->parameters_client_->wait_for_service(20s)) {
ASSERT_TRUE(false) << "service not available after waiting";
Copy link
Member

Choose a reason for hiding this comment

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

I saw that you copied it from above but do you know why we don't just use FAIL() here?
FAIL() << "service not available after waiting";

Copy link
Member Author

Choose a reason for hiding this comment

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

perhaps it doesn't allow a message (it's only used as FAIL() elsewhere FWICS)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah we can look into what the differences are at a future date.

Note to future-self @mikaelarguedas: consider replacing those in the future by FAIL() or ADD_FAILURE() based on context.
references: places where we use it, gtest example

@dhood
Copy link
Member Author

dhood commented Dec 4, 2017

this PR still needs review

CI OS X including a1ea944: Build Status

Copy link
Member

@wjwwood wjwwood left a comment

Choose a reason for hiding this comment

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

I had a suggestion for a slightly better implementation of the tests, but also lgtm as-is.

executor.add_node(node);
node->queue_set_parameter_request(executor);
// When the parameters client receives its response it will cancel the executor.
executor.spin();
Copy link
Member

Choose a reason for hiding this comment

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

The only issue here is that there is no timeout for the spin. If the callback is not called the test will hang.

You could instead:

  • create a promise and a future from the promise
  • pass the promise to queue_set_parameter_request
  • capture the promise in the lambda callback
  • set the promise in the lambda callback
  • spin_until_future_complete on the future and with a timeout
  • assert the future is set after spin_until_future_complete returns (i.e. assert it didn't timeout)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the idea, I wasn't aware of this way to make the test fail in a way other than timeout: it's a better approach since this test file has a really long time out because of all the wait_for_service calls. I won't have time to update this tonight (and the test shouldn't be failing as it stands) so I'll still merge as is for now

@dhood dhood merged commit 772325a into master Dec 4, 2017
@dhood dhood deleted the parameter_client_callback_ref branch December 4, 2017 03:26
@dhood dhood removed the in review Waiting for review (Kanban column) label Dec 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants