Skip to content

Conversation

@LastStarDust
Copy link
Contributor

@LastStarDust LastStarDust commented Mar 1, 2023

I created this pull request as a proof of concept for the new feature discussed here: #348.
The ticket description is still correct and relevant, but for clarity's sake, let me summarize and expand on it here.

Let us assume there is a node ("NODE under test" in the diagram) which:

  • takes a topic A as input
  • does some calculation
  • publishes another topic B as output

At the moment, there is no way to programmatically test the whole node end-to-end. For that, we need a way to:

  1. inject a message of topic A into the node
  2. wait for the calculation to be over
  3. collect the resulting message of topic B coming out of the node

Currently, the WaitForTopics class provided by this package takes care of 2 and 3, but there is no mechanism to reliably accomplish 1, due to the asynchronous nature of ROS2 publishers and subscribers.

This PR is an attempt to enhance the WaitForTopics class so that it can take care of 1 as well, thus closing the loop. But it might well not be the only solution or the most effective. I am open to any kind of suggestion and guidance.

The main issue behind the implementation of such a feature is that in ROS2 the order of creation of publishers and subscribers does matter. They must either always be created in a specific order or be synchronized in some other way.

Below is a cartoon-style diagram illustrating what the end result should look like:

node-test-diagram

@LastStarDust LastStarDust changed the title Let the user inject callables after starting subscribers WaitForTopics: let the user inject callables after starting subscribers Mar 1, 2023
Copy link
Contributor

@adityapande-1995 adityapande-1995 left a comment

Choose a reason for hiding this comment

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

I've posted some questions worth discussing here : #348 (comment)

@LastStarDust
Copy link
Contributor Author

I've posted some questions worth discussing here : #348 (comment)

@adityapande-1995 @clalancette I have added a more comprehensive sample code in commit 5aa51d7

@LastStarDust
Copy link
Contributor Author

@adityapande-1995 @clalancette
Hello and sorry for the comment. Is there anything I can do to help with the review of this pull request?

@LastStarDust LastStarDust force-pushed the feature/inject-callables branch from 3f96cb5 to b8004ab Compare May 22, 2023 04:30
@LastStarDust
Copy link
Contributor Author

@osrf-jenkins retest this please

@LastStarDust
Copy link
Contributor Author

@adityapande-1995 @clalancette
Let me present a thought experiment that might make clearer what I am trying to achieve with this pull request.

How would you test a node that is subscribed to a topic with a single int field, that publishes the same topic where the int was incremented by one?

@LastStarDust
Copy link
Contributor Author

@osrf-jenkins retest this please

@LastStarDust
Copy link
Contributor Author

@adityapande-1995 @methylDragon
Friendly reminder about this PR.

Until now, I have been using my fork at work for our project, but it would give us more confidence if we could just use the official repository, or even better if this PR could end up in the released version on https://index.ros.org/packages/.

@LastStarDust
Copy link
Contributor Author

@osrf-jenkins retest this please

@adityapande-1995
Copy link
Contributor

@LastStarDust my apologies, taking a look now

@LastStarDust LastStarDust changed the title WaitForTopics: let the user inject callables after starting subscribers WaitForTopics: let the user inject callables to be executed after starting the subscribers Feb 1, 2024
@LastStarDust
Copy link
Contributor Author

@adityapande-1995 @methylDragon I fixed some linting errors and now the checks are finally passing.

@Ryanf55
Copy link

Ryanf55 commented Feb 15, 2024

Hello, could we get a maintainer to look at this PR?

@LastStarDust LastStarDust changed the title WaitForTopics: let the user inject callables to be executed after starting the subscribers WaitForTopics: let the user inject callabacks to be executed after starting the subscribers Feb 16, 2024
@LastStarDust LastStarDust changed the title WaitForTopics: let the user inject callabacks to be executed after starting the subscribers WaitForTopics: let the user inject a callaback to be executed after starting the subscribers Feb 16, 2024
@mjcarroll
Copy link
Member

@methylDragon is OOO, but I will ping him to look when he is back.

Copy link

@Ryanf55 Ryanf55 left a comment

Choose a reason for hiding this comment

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

I tested this on a backport in humble in our own CI and it is very reliable with some minor mods.

@LastStarDust
Copy link
Contributor Author

LastStarDust commented Jul 3, 2024

@Ryanf55 Hello, I would like to resume working on this PR. Could you please take a look at the conversations you opened and resolve the ones you think are resolved?

@LastStarDust
Copy link
Contributor Author

@osrf-jenkins retest this please

@Ryanf55
Copy link

Ryanf55 commented Jul 9, 2024

@Ryanf55 Hello, I would like to resume working on this PR. Could you please take a look at the conversations you opened and resolve the ones you think are resolved?

Yep, all of the issues we found are still problems, and we never found a good workaround for doing this generically in humble. For now, we disabled our python automated testing as a requirement for PR's because this problem is so difficult to deal with, and have focused testing without the middleware. Once we can move to Jazzy, then the event handlers should make this kind of testing much more reliable because you can do a proper wait on the interfaces to come up.

Sorry, we've just spent an exorbitant amount of time on this trying to get this reliable in humble and could never figure out a way that wasn't extremely coupled to knowing exactly what was running and manual graph introspection hard-coded into our test framework. I'm optimistic that upgrading distros will make it easier, but this way of testing in python is not something we're going to pursue any further unless anyone can give us a reasonable approach that works without hard-coded timeouts/sleeps for discovery that fail on slower runners.

@LastStarDust
Copy link
Contributor Author

@Ryanf55 Thank you for sharing the situation. I am sorry we could not figure out how to make this work reliably in Humble.
Anyway, can I resolve the discussions opened by you in this PR, since it applies to rolling?

LastStarDust and others added 7 commits April 15, 2025 00:54
Signed-off-by: Giorgio Pintaudi <[email protected]>

Updates the `WaitForTopics` class to use the term 'trigger' instead of 'callback' for the function executed during the wait.

This change clarifies the function's purpose, which is to trigger an action rather than simply provide a callback.
Signed-off-by: Giorgio Pintaudi <[email protected]>

Passes the timeout value to the `any_publisher_connected.wait()` call.
This ensures that the wait for any publisher connection respects the
specified timeout, preventing indefinite blocking.
Signed-off-by: Giorgio Pintaudi <[email protected]>

Allows specifying a namespace for the internal node
created by `WaitForTopics`. This enables better
organization and avoids potential naming conflicts
when using `wait_for_topics` in complex launch setups.
Signed-off-by: Giorgio Pintaudi <[email protected]>

Co-authored-by: Christophe Bedard <[email protected]>
Signed-off-by: Giorgio Pintaudi <[email protected]>
Signed-off-by: Giorgio Pintaudi <[email protected]>

Co-authored-by: Christophe Bedard <[email protected]>
Signed-off-by: Giorgio Pintaudi <[email protected]>
Signed-off-by: Giorgio Pintaudi <[email protected]>

Adds a blank line after the disable-windows-cli-blocking pragma for improved code style and readability.
@mergify
Copy link

mergify bot commented Apr 15, 2025

rebase

✅ Branch has been successfully rebased

@christophebedard christophebedard force-pushed the feature/inject-callables branch from d8866da to 3c52fdd Compare April 15, 2025 00:54
@LastStarDust
Copy link
Contributor Author

LastStarDust commented Apr 15, 2025

@christophebedard I think the DCO check is failing after your rebase. I am not sure how to fix that. My guess is that you need to add your sign to each commit.

@christophebedard
Copy link
Member

It's OK, I can just manually set it to pass.

@christophebedard
Copy link
Member

Pulls: #356
Gist: https://gist.githubusercontent.com/christophebedard/ce2a429b7640973274d34dc3ad9a9838/raw/6af87c7d846ad03e8f86b90fe1e969c071163a64/ros2.repos
BUILD args: --packages-above-and-dependencies launch_testing_ros
TEST args: --packages-above launch_testing_ros
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/15697

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

Copy link
Member

@christophebedard christophebedard left a comment

Choose a reason for hiding this comment

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

Alright, I think this PR is in a good state and I think the approach helps reduce flakiness.

Let's see if CI passes.

@christophebedard
Copy link
Member

The ros2param test failures are known.

@christophebedard christophebedard merged commit 1e33f0a into ros2:rolling Apr 15, 2025
3 checks passed
@christophebedard
Copy link
Member

@LastStarDust it might be worth updating/expanding the integration testing tutorial added in ros2/ros2_documentation#4881 to show an example of WaitForTopics (ros2/ros2_documentation#4881 (comment)) instead of simply mentioning it. Let me know if you'd be willing to do that, otherwise I will open an issue!

@christophebedard
Copy link
Member

I created an issue for it: ros2/ros2_documentation#5249

@LastStarDust
Copy link
Contributor Author

LastStarDust commented Apr 24, 2025

@christophebedard Yes, I am available to improve the documentation. I hope more people become interested in integration testing of ROS2 nodes, and as a result, we will see more advanced and flexible tooling developed.

@LastStarDust LastStarDust deleted the feature/inject-callables branch May 12, 2025 09:25
@christophebedard
Copy link
Member

@LastStarDust do you still want this PR to be backported to Jazzy? I got an email notification, but I can't find your comment anymore

@LastStarDust
Copy link
Contributor Author

LastStarDust commented Jun 22, 2025

@christophebedard
I deleted that comment because I found a (small) bug in this PR in the meanwhile. I am going to open a new PR with the bugfix (#474)

Once all the bugs are ironed out and I am 100% sure this is working as intended, then we can port this to Jazzy.

@ahcorde
Copy link
Contributor

ahcorde commented Nov 19, 2025

https://github.com/Mergifyio backport kilted jazzy

@mergify
Copy link

mergify bot commented Nov 19, 2025

backport kilted jazzy

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Nov 19, 2025
…d after starting the subscribers (#356)

Signed-off-by: Giorgio Pintaudi <[email protected]>
(cherry picked from commit 1e33f0a)
ahcorde pushed a commit that referenced this pull request Nov 20, 2025
… starting the subscribers (backport #356) (#504)

* `WaitForTopics`: let the user inject a trigger function to be executed after starting the subscribers (#356)

Signed-off-by: Giorgio Pintaudi <[email protected]>
(cherry picked from commit 1e33f0a)
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.

10 participants