rclcpp icon indicating copy to clipboard operation
rclcpp copied to clipboard

Make the subscriber_triggered_to_receive_message test more reliable.

Open clalancette opened this issue 1 year ago • 1 comments

In the current code, inside of the timer we create the subscription and the publisher, publish immediately, and expect the subscription to get it immediately. But it may be the case that discovery hasn't even happened between the publisher and the subscription by the time the publish call happens.

To make this more reliable, create the subscription and publish before we ever create and spin on the timer. This at least gives 100 milliseconds for discovery to happen. That may not be quite enough to make this reliable on all platforms, but in my local testing this helps a lot. Prior to this change I can make this fail one out of 10 times, and after the change I've run 100 times with no failures.

FYI @iuhilnehc-ynos .

@wjwwood If you have time to look at this, I'd appreciate a review.

@Crola1702 FYI, this should fix the flaky test https://ci.ros2.org/view/nightly/job/nightly_linux_repeated/3515/testReport/junit/rclcpp/TestAddCallbackGroupsToExecutorStable_MultiThreadedExecutor/subscriber_triggered_to_receive_message/

clalancette avatar Jul 12 '24 15:07 clalancette

Should we force waiting until discovery happens? For example

while (publisher->get_subscription_count() == 0) {
    std::this_thread::sleep_for(std::chrono::milliseconds(5));
}

alsora avatar Jul 13 '24 16:07 alsora

Should we force waiting until discovery happens?

Yeah, that's fair. I'm actually going to change the timer callback to check for discovery to happen.

clalancette avatar Jul 22 '24 11:07 clalancette

CI:

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

clalancette avatar Jul 22 '24 14:07 clalancette