-
Notifications
You must be signed in to change notification settings - Fork 493
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
Tests for CurrentStateMonitor using dependency injection #562
Conversation
42129dd
to
e241c3f
Compare
Codecov Report
@@ Coverage Diff @@
## main #562 +/- ##
==========================================
+ Coverage 46.64% 46.72% +0.08%
==========================================
Files 183 184 +1
Lines 19667 19685 +18
==========================================
+ Hits 9171 9195 +24
+ Misses 10496 10490 -6
Continue to review full report at Codecov.
|
moveit_ros/planning/planning_scene_monitor/test/current_state_monitor_tests.cpp
Outdated
Show resolved
Hide resolved
moveit_ros/planning/planning_scene_monitor/test/current_state_monitor_tests.cpp
Show resolved
Hide resolved
moveit_ros/planning/planning_scene_monitor/test/current_state_monitor_tests.cpp
Outdated
Show resolved
Hide resolved
moveit_ros/planning/planning_scene_monitor/test/current_state_monitor_tests.cpp
Outdated
Show resolved
Hide resolved
moveit_ros/planning/planning_scene_monitor/test/current_state_monitor_tests.cpp
Outdated
Show resolved
Hide resolved
c193102
to
9743f18
Compare
0006dc8
to
34a4a8c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RCL is already a wrapper around DDS or other middlewares. Now we are creating a wrapper for the wrapper, in the name of testing? Does this kind of functionality belong in core ROS2, rather than a one-off implementation in this one MoveIt class? This type of new complexity in the name of testing does not seem like a good idea to me, in terms of long term maintenance. What's a solution we can use for all of MoveIt? Or for all ROS applications?
...lanning/planning_scene_monitor/include/moveit/planning_scene_monitor/current_state_monitor.h
Show resolved
Hide resolved
/** | ||
* @brief This class contains the rcl interfaces for easier testing | ||
*/ | ||
class RclInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a better name?
class RclInterface | |
class RclTestInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just for testing right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class seems like a generic tool that should not be specific to the CurrentStateMonitor. Maybe it should live in moveit_core/utils ?
namespace planning_scene_monitor | ||
{ | ||
/** | ||
* @brief This class contains the rcl interfaces for CurrentStateMontior |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not very descriptive... the words you used here are all in the file name. Be more helpful to future developers, like:
* @brief This class contains the rcl interfaces for CurrentStateMontior | |
* @brief Dependency injection method for testing the CurrentStateMonitor |
} | ||
else | ||
{ | ||
return ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this also throw/print an error, if the string is undefined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a change in behavior (this is a straight copy-paste of code from current_state_monitor)
My original idea was to use the abstract interfaces in
Increasing maintenance cost (more complex code) in exchange for better testing seems like a good tradeoff to me. With out dependency injection, we can't test these parts of the code without creating rostests. The downside to rostests is they are executing a bunch of code within ros and therefore our tests can go flaky when there are changes within ros. This is the situation with a the tests in moveit_servo and the ompl constraint planner on foxy. With dependency injection we can write tests that only test the code in moveit without testing ros itself.
This pattern is something we can use for all of moveit. It adds complexity to the implementation of various classes without changing the interfaces of those classes in exchange for tests of the behavior in those classes. We are currently debugging a concurrency issue inside PlanningSceneMonitor for a client that with this pattern we will be able to add tests to isolate (and fix) those issues. This PR is very limited in its scope and does not include in depth testing of CurrentStateMonitor. That was intentional as we are using this PR as a pattern for how to add the infrastructure for dependency injection based unit tests. Another benefit of this which I think @v4hn (and @henningkayser and @JafarAbdi who have been doing the syncs) will especially like is that it should make syncing improvements between ros1 and ros2 versions of moveit much easier (after these tests are backported, which should be fairly trivial). The reason for this is it isolates the ROS code to these MiddlewareHandle implementation classes from the actual logic in moveit itself. |
Description
This is mostly about demonstrating a pattern for using dependency injection to be able to unit test sections of the code with ros dependencies in a unit test.
Checklist