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

Ros2 unit test workflow #471

Merged
merged 26 commits into from
Jan 28, 2025
Merged

Ros2 unit test workflow #471

merged 26 commits into from
Jan 28, 2025

Conversation

delihus
Copy link
Contributor

@delihus delihus commented Dec 17, 2024

Description

  • Added unit test workflow on push
  • Moved some tests to TEST_INTEGRATION

Requirements

  • Code style guidelines followed
  • Documentation updated

Tests 🧪

  • Robot
  • Container
  • Simulation

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a new GitHub Actions workflow for automated unit testing
    • Enhanced battery driver node with namespace configuration
  • Documentation

    • Updated README with detailed unit testing instructions for laptop and Built-In Computer
  • Testing

    • Transitioned to Google Mock for more robust unit testing
    • Introduced conditional integration test configurations
    • Refined test execution strategies across multiple packages
  • Chores

    • Removed unused ROS 2 dependencies in some components
    • Simplified test return value handling

delihus and others added 17 commits November 12, 2024 19:42
Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>
Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>
Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>
Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>
Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>
Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>
Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>
Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>
Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>
Copy link
Contributor

coderabbitai bot commented Dec 17, 2024

Walkthrough

This pull request introduces comprehensive changes to the project's testing infrastructure and workflow. A new GitHub Actions workflow for running unit tests has been added, replacing an existing workflow. The changes span multiple packages, including modifications to CMakeLists.txt files to adjust test configurations, updates to the battery driver node's constructor, and refinements to test utilities. The primary focus is on enhancing the testing process, with a particular emphasis on conditional integration testing and improved test execution methods.

Changes

File Change Summary
.github/workflows/run-unit-tests.yaml New GitHub Actions workflow for automated unit testing
.github/workflows/unit-tests.yaml Deleted existing workflow file
README.md Added sections for unit testing on laptop and Built-In Computer
husarion_ugv_battery/include/husarion_ugv_battery/battery_driver_node.hpp
husarion_ugv_battery/src/battery_driver_node.cpp
Updated BatteryDriverNode constructor to support namespace
husarion_ugv_battery/test/utils/test_battery_driver_node.hpp Updated test class to include namespace parameter in BatteryDriverNode instantiation and improved file handling in WriteNumberToFile method
husarion_ugv_diagnostics/CMakeLists.txt Set TEST_INTEGRATION to OFF
husarion_ugv_hardware_interfaces/CMakeLists.txt Transitioned from ament_add_gtest to ament_add_gmock, added new test configurations
husarion_ugv_manager/CMakeLists.txt Added TEST_INTEGRATION option, modified test configurations
Various test files Minor modifications to test execution and header inclusions

Suggested Reviewers

  • KmakD
  • rafal-gorecki

Possibly related PRs


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1fdc675 and bcf68eb.

📒 Files selected for processing (1)
  • .github/workflows/run-unit-tests.yaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/run-unit-tests.yaml
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Run unit tests hardware build type
  • GitHub Check: Run unit tests simulation build type

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@delihus delihus changed the base branch from ros2 to ros2-devel December 17, 2024 20:53
Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>
…workflow

Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>
…workflow

Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>
@rafal-gorecki rafal-gorecki self-requested a review January 21, 2025 10:15
Copy link
Contributor

@rafal-gorecki rafal-gorecki left a comment

Choose a reason for hiding this comment

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

Please check and merge: suggestions with test corrections:

rafal-gorecki and others added 3 commits January 23, 2025 11:53
* Test unit test

* Add debuging logs

* Change in test deconstructor

* test

* Test

* test

* Utest

* Add test namespace

* console_cohesion-

* test

* Test

* Update run-unit-tests-push.yaml

* Simplify

* Simplify NodeCreation test

* Move system_ros_interface to integration test

* Fix

* Remove redundant workflow
Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>
@delihus delihus marked this pull request as ready for review January 24, 2025 11:14
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
husarion_ugv_battery/test/utils/test_battery_driver_node.hpp (1)

106-106: Consider removing the leading slash in namespace for consistency.
You are instantiating BatteryDriverNode with "/test_battery" as the namespace. While correct, consider removing the leading slash if you prefer a relative namespace or if you want consistency with other packages.

.github/workflows/run-unit-tests.yaml (1)

1-42: Efficient CI configuration with potential for caching.
The new workflow appears solid, providing a matrix strategy for simulation and hardware builds. Consider adding caching (e.g., for built packages or dependencies) to accelerate repeated runs.

husarion_ugv_manager/CMakeLists.txt (1)

167-167: Consider generalizing the option description.

The current description "Run tests on self hosted runner" is specific to CI environment. Consider using a more general description like "Run integration tests" to match other packages and make it clear that this controls integration test execution regardless of the environment.

-  option(TEST_INTEGRATION "Run tests on self hosted runner" OFF)
+  option(TEST_INTEGRATION "Run integration tests" OFF)
husarion_ugv_hardware_interfaces/CMakeLists.txt (1)

227-247: Consider consistent test framework usage.

The integration test section mixes ament_add_gtest and ament_add_gmock. While both frameworks are valid, consider using ament_add_gmock consistently as it's a superset of gtest and provides mocking capabilities that might be useful in future test expansions.

For example, these tests could be converted to use gmock:

  • ${PROJECT_NAME}_test_system_ros_interface
  • ${PROJECT_NAME}_test_canopen_manager
  • ${PROJECT_NAME}_test_roboteq_driver

Also applies to: 249-255, 257-268, 277-343

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 498a2c2 and bc7950b.

📒 Files selected for processing (12)
  • .github/workflows/run-unit-tests.yaml (1 hunks)
  • .github/workflows/unit-tests.yaml (0 hunks)
  • README.md (2 hunks)
  • husarion_ugv_battery/include/husarion_ugv_battery/battery_driver_node.hpp (1 hunks)
  • husarion_ugv_battery/src/battery_driver_node.cpp (1 hunks)
  • husarion_ugv_battery/test/utils/test_battery_driver_node.hpp (2 hunks)
  • husarion_ugv_diagnostics/CMakeLists.txt (1 hunks)
  • husarion_ugv_hardware_interfaces/CMakeLists.txt (2 hunks)
  • husarion_ugv_manager/CMakeLists.txt (1 hunks)
  • husarion_ugv_manager/include/husarion_ugv_manager/behavior_tree_manager.hpp (0 hunks)
  • husarion_ugv_manager/test/test_behavior_tree_manager.cpp (1 hunks)
  • husarion_ugv_manager/test/test_behavior_tree_utils.cpp (1 hunks)
💤 Files with no reviewable changes (2)
  • husarion_ugv_manager/include/husarion_ugv_manager/behavior_tree_manager.hpp
  • .github/workflows/unit-tests.yaml
✅ Files skipped from review due to trivial changes (2)
  • husarion_ugv_manager/test/test_behavior_tree_utils.cpp
  • husarion_ugv_manager/test/test_behavior_tree_manager.cpp
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Run unit tests hardware build type
  • GitHub Check: Run unit tests simulation build type
🔇 Additional comments (7)
husarion_ugv_battery/include/husarion_ugv_battery/battery_driver_node.hpp (1)

41-42: Empower user-defined namespace with caution.
The new optional ns parameter for BatteryDriverNode looks good for configurability. Be mindful, however, that including a leading slash ("/") can occasionally lead to unexpected fully qualified names. Ensure that this usage is consistent with the broader ROS 2 naming conventions across the codebase.

husarion_ugv_battery/src/battery_driver_node.cpp (1)

39-41: Constructor signature aligns with ROS 2 best practices.
Initializes the node correctly by passing node_name, ns, and options to the base class constructor. No issues found.

husarion_ugv_battery/test/utils/test_battery_driver_node.hpp (1)

139-146: Robust file I/O error handling appreciated.
The two-step validation (checking if the file was created successfully and if writing was successful) is good. This ensures clear messaging in case of errors.

husarion_ugv_diagnostics/CMakeLists.txt (1)

76-76: LGTM! Good separation of integration tests.

The addition of the TEST_INTEGRATION option with default OFF is a good practice for controlling the execution of integration tests. This aligns with the PR objectives and follows standard CMake practices.

husarion_ugv_manager/CMakeLists.txt (1)

168-187: LGTM! Well-organized test structure.

The integration tests are properly organized under the TEST_INTEGRATION condition. This separation allows for better control over test execution and aligns with the PR objectives.

husarion_ugv_hardware_interfaces/CMakeLists.txt (1)

224-225: LGTM! Clear separation of integration tests.

The integration tests section is well-marked and the TEST_INTEGRATION option is properly configured with default OFF.

README.md (1)

140-152: LGTM! Clear and comprehensive testing instructions.

The new sections provide clear instructions for running tests in different environments. The documentation properly explains the usage of the TEST_INTEGRATION flag and aligns well with the code changes.

@delihus delihus requested a review from rafal-gorecki January 27, 2025 09:21
Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bc7950b and 1fdc675.

📒 Files selected for processing (1)
  • .github/workflows/run-unit-tests.yaml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/run-unit-tests.yaml

47-47: property "build_test_1" is not defined in object type {}

(expression)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Run unit tests hardware build type
  • GitHub Check: Run unit tests simulation build type
🔇 Additional comments (4)
.github/workflows/run-unit-tests.yaml (4)

1-8: LGTM! Well-configured workflow triggers.

The workflow triggers are appropriately set up to run on push events while also allowing manual triggering and reuse in other workflows.


9-16: LGTM! Effective use of matrix strategy.

The matrix strategy efficiently handles both simulation and hardware builds, with clear job naming for easy identification in CI logs.


17-27: LGTM! Proper environment setup for ROS 2 testing.

The environment configuration is well-structured with appropriate action versions and ROS 2 testing enabled.


28-43: Verify the existence of build-specific dependency files.

Please ensure that both simulation_deps.repos and hardware_deps.repos files exist in the husarion_ugv directory.

✅ Verification successful

Build dependency files are correctly configured

Both simulation_deps.repos and hardware_deps.repos files exist in the husarion_ugv directory, confirming that the workflow configuration is correct.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if both deps files exist
ls -l husarion_ugv/simulation_deps.repos husarion_ugv/hardware_deps.repos

Length of output: 241

}
}

continue-on-error: true
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Reconsider using continue-on-error: true.

Using continue-on-error: true might hide build or test failures. Consider removing it since you already have a retry mechanism in place.

-        continue-on-error: true

Comment on lines +46 to +61
- name: Retry Build and test (if failed)
if: steps.build_test_1.outcome == 'failure'
uses: ros-tooling/action-ros-ci@v0.3
with:
vcs-repo-file-url: ${{ github.workspace }}/husarion_ugv/${{ env.HUSARION_ROS_BUILD_TYPE }}_deps.repos
target-ros2-distro: humble
colcon-defaults: |
{
"build": {
"packages-up-to": ["husarion_ugv"],
"cmake-args": ["-DCMAKE_BUILD_TYPE=Release"]
},
"test": {
"packages-up-to": ["husarion_ugv"]
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the retry condition step ID reference.

The condition references an undefined step ID build_test_1. The previous step needs an ID to be referenced in the retry condition.

Apply this diff to fix the step ID reference:

      - name: Build and test
+       id: build_test_1
        uses: ros-tooling/action-ros-ci@v0.3

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 actionlint (1.7.4)

47-47: property "build_test_1" is not defined in object type {}

(expression)

Copy link
Contributor

@rafal-gorecki rafal-gorecki left a comment

Choose a reason for hiding this comment

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

It's not working, test allways pass:
image
ChatGPT suggest to add: id: build_test_1 to step

Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>
@delihus delihus requested a review from rafal-gorecki January 28, 2025 11:53
@rafal-gorecki rafal-gorecki merged commit 6711cab into ros2-devel Jan 28, 2025
3 checks passed
@rafal-gorecki rafal-gorecki deleted the ros2-unit-test-workflow branch January 28, 2025 13:00
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