Skip to content

Add in tests for the static executor#1331

Merged
clalancette merged 5 commits intomasterfrom
clalancette/test-static-executor
Sep 25, 2020
Merged

Add in tests for the static executor#1331
clalancette merged 5 commits intomasterfrom
clalancette/test-static-executor

Conversation

@clalancette
Copy link
Copy Markdown
Contributor

This PR adds in tests for the StaticSingleThreadedExecutor and a helper class, StaticExecutorEntitiesCollector. With this PR in place, I see 97% line coverage on static_single_threaded_executor.cpp and 97% line coverage on static_executor_entities_collector.cpp.

Along the way, I found a few bugs and other problems that I've fixed:

  1. There were some typos in comments.
  2. There were a bunch of places where we could add const to variables to give the compiler a bit more of a hint.
  3. There were a couple of places where we were calling the copy constructor when passing a map into a method.
  4. There was a bug when calculating whether to add a guard condition after adding a new node.

Note that this is still in draft because I want to run CI on it (particularly for Windows). I'll pull it out of draft once CI comes back clean.

@clalancette
Copy link
Copy Markdown
Contributor Author

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Copy link
Copy Markdown
Contributor

@brawner brawner left a comment

Choose a reason for hiding this comment

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

Most of my comments are just due to some formatting that seems a bit different then I've seen elsewhere in rclcpp. Also, I'm curious whether this makes sense as several PRs rather than just one larger one.


TEST_F(TestStaticExecutorEntitiesCollector, add_callback_group) {
auto node = std::make_shared<rclcpp::Node>("node1", "ns");
rclcpp::CallbackGroup::SharedPtr cb_group = node->create_callback_group(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A bit of a nitpick here, but I think using auto would let you put these two lines onto one, which would help readability a small bit with all these new tests. Likewise, I would recommend to avoid abbreviations like 'cb_group' if possible (either group or callback_group). Fix here and below

Copy link
Copy Markdown
Contributor Author

@clalancette clalancette Sep 24, 2020

Choose a reason for hiding this comment

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

Would that actually work, though? If I do that, then the node pointer becomes a temporary, and then wouldn't it be destroyed immediately after this line (since there are no more handles to it)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We discussed this offline. @brawner was suggesting that I combine this line with the next one by using auto. My personal preference is to not use auto, so I think we'll just leave this here for now. @brawner Let me know if you disagree.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Disagreements about the awesomeness and power of auto in a unit test aside, I'm fine leaving these as is.

auto subscription =
node->create_subscription<test_msgs::msg::Empty>(
"topic", rclcpp::QoS(10), [](test_msgs::msg::Empty::SharedPtr) {});
auto timer =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: was this line break intentional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure about this one. uncrustify definitely told me to make this change, though you are right that it can probably be collapsed to one line.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Strange, uncrustify is happy with this on my machine,

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

@clalancette
Copy link
Copy Markdown
Contributor Author

Most of my comments are just due to some formatting that seems a bit different then I've seen elsewhere in rclcpp.

I honestly just write code in my own style, and then do what uncrustify tells me to make it pass the linters. It is often the case that several things would satisfy uncrustify, but I just always take the one it tells me to do.

Also, I'm curious whether this makes sense as several PRs rather than just one larger one.

Yeah, I debated about that. I decided to put it into a single PR for a few reasons:

  1. These changes did come up while writing the tests here, so they are mostly related.
  2. My plan was to "Rebase and Merge" this set so that they are individual commits.
  3. Expediency.

If you'd still like me to split it up, how many more PRs would you suggest? I can see arguments for 1, 2, 3, 4, or 5 :).

@clalancette clalancette force-pushed the clalancette/test-static-executor branch from 83c1414 to cc6ffde Compare September 24, 2020 20:13
@brawner
Copy link
Copy Markdown
Contributor

brawner commented Sep 24, 2020

how many more PRs would you suggest?

I waffled myself on how many would make sense. I think separating out the API changes would be good and then you can tag some reviewers that might have more insight into the intended use of these classes than myself. Otherwise, it's just a matter of backportability.

When adding coverage our general guiding principle has been that bugs should be back portable to whatever ros distro's make sense and tests should be backportable to foxy. However, I was under the impression you were adding coverage for stuff mostly added only in rolling, so separating out into more PRs might not provide much benefit.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
We need to determine if this is a new node *before* adding
it to the list; otherwise, it will always be treated as an old
node.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
We get to 97% code coverage with these tests in place.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
@clalancette clalancette force-pushed the clalancette/test-static-executor branch from cc6ffde to bb4cb74 Compare September 25, 2020 14:01
@clalancette
Copy link
Copy Markdown
Contributor Author

All right, I've rebased and left only the changes that don't affect API here. I'll open a separate PR for the API changes presently. I'm going to mark this as an in-progress PR now, and run another round of CI here.

@clalancette clalancette marked this pull request as ready for review September 25, 2020 14:03
@clalancette
Copy link
Copy Markdown
Contributor Author

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

auto subscription =
node->create_subscription<test_msgs::msg::Empty>(
"topic", rclcpp::QoS(10), [](test_msgs::msg::Empty::SharedPtr) {});
auto timer =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Strange, uncrustify is happy with this on my machine,

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


TEST_F(TestStaticExecutorEntitiesCollector, add_callback_group) {
auto node = std::make_shared<rclcpp::Node>("node1", "ns");
rclcpp::CallbackGroup::SharedPtr cb_group = node->create_callback_group(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Disagreements about the awesomeness and power of auto in a unit test aside, I'm fine leaving these as is.

@clalancette clalancette merged commit 148d295 into master Sep 25, 2020
@delete-merged-branch delete-merged-branch bot deleted the clalancette/test-static-executor branch September 25, 2020 19:42
@clalancette
Copy link
Copy Markdown
Contributor Author

Thanks for the reviews!

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.

2 participants