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 executor unit tests #1336

Merged
merged 3 commits into from
Sep 28, 2020
Merged

Add executor unit tests #1336

merged 3 commits into from
Sep 28, 2020

Conversation

clalancette
Copy link
Contributor

This PR adds in unit tests for the Executor class. With this change in place, I'm seeing 91% line coverage of the executor.cpp file.

Besides a handful of single lines that aren't being covered, there is a big chunk of missing coverage in the execute_subscription method. I think this is going to be a lot of work to cover, so I figured I would open what I have so far and we can iterate on that later.

@clalancette
Copy link
Contributor Author

CI:

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

Copy link
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.

Looks good to me, just a couple of questions

// Wait for the wall timer to have expired.
std::this_thread::sleep_for(std::chrono::milliseconds(50));
EXPECT_FALSE(timer_fired);
dummy.spin_nanoseconds(node->get_node_base_interface());
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not very familiar with spin_once, but is it possible that spin_once for different rmw implementations that there are other tasks that get taken care of here, or is expected that this timer will fire here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is that spin_once collects all of the entities that could possibly be executed, and then picks one to execute from a fixed-priority list:

Executor::execute_any_executable(AnyExecutable & any_exec)
.

Since timers are always the first thing in the priority list, then the only way we could not execute this is if some other entity added a timer to the executor before this one. But I don't think that can currently happen.

There is a lot of interest in removing that fixed-priority scheme and make it something else (FIFO, or whatever). If that happens, then there is a small possibility that this test won't work anymore, but I think it is pretty unlikely.

node->create_wall_timer(std::chrono::milliseconds(1), [&timer_fired]() {timer_fired = true;});

// Wait for the wall timer to have expired.
std::this_thread::sleep_for(std::chrono::milliseconds(50));
Copy link
Contributor

Choose a reason for hiding this comment

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

Just taking into account how long rclcpp already takes for tests to run, can these sleeps be shorter (like 2ms or 10ms)? Or do you think it would be flaky?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think that 2ms is going to be enough. 10ms is probably enough, but I really didn't want to introduce a flaky test here (particularly on Windows, where timers are really jittery).

Just as a datapoint, this entire file full of tests takes 842ms to run on my machine. If I were to change all of these 50ms sleeps to 10ms, then I'd save ~210ms. Its a good chunk, but I think the resistance to flakiness is more important.

Copy link
Contributor

Choose a reason for hiding this comment

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

Very true, and 210ms is peanuts all told. I just thought it was not great practice to depend on sleeps for behavior tests, but I also couldn't think of a way to assert the proper behavior. FWIW on my machine, these tests all pass even removing this sleep.

rclcpp/test/rclcpp/test_executor.cpp Show resolved Hide resolved
Copy link
Contributor

@Blast545 Blast545 left a comment

Choose a reason for hiding this comment

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

LGTM

typename ArgT2, typename ArgT3,
typename ArgT4, typename ArgT5,
typename ArgT6, typename ArgT7>
struct PatchTraits<ID, ReturnT(ArgT0, ArgT1, ArgT2, ArgT3, ArgT4, ArgT5, ArgT6, ArgT7)>
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI: I added those in #1330, one of us will have to rebase it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good to know, thanks for the heads up.

In particular, make sure to use 'throw_from_rcl_error'
as much as possible.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
This will be needed by the executor tests.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
@clalancette
Copy link
Contributor Author

One more CI:

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

@clalancette clalancette merged commit 175bc64 into master Sep 28, 2020
@delete-merged-branch delete-merged-branch bot deleted the clalancette/test-executor branch September 28, 2020 19:17
brawner added a commit that referenced this pull request Oct 9, 2020
* Improve the error messages in the Executor class.

In particular, make sure to use 'throw_from_rcl_error'
as much as possible.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>

* Allow mimick patching of methods with up to 9 arguments.

This will be needed by the executor tests.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>

* Add in unit tests for the Executor class.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>

* Adjust test_executor for foxy

Signed-off-by: Stephen Brawner <brawner@gmail.com>

Co-authored-by: Chris Lalancette <clalancette@openrobotics.org>
brawner added a commit that referenced this pull request Oct 19, 2020
* Improve the error messages in the Executor class.

In particular, make sure to use 'throw_from_rcl_error'
as much as possible.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>

* Allow mimick patching of methods with up to 9 arguments.

This will be needed by the executor tests.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>

* Add in unit tests for the Executor class.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>

* Adjust test_executor for foxy

Signed-off-by: Stephen Brawner <brawner@gmail.com>

Co-authored-by: Chris Lalancette <clalancette@openrobotics.org>
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