Skip to content

test: remove unnecessary sleep in waitable test#3111

Open
Anusha-Sharma-2 wants to merge 2 commits intoros2:rollingfrom
Anusha-Sharma-2:fix-test-waitable-sleep
Open

test: remove unnecessary sleep in waitable test#3111
Anusha-Sharma-2 wants to merge 2 commits intoros2:rollingfrom
Anusha-Sharma-2:fix-test-waitable-sleep

Conversation

@Anusha-Sharma-2
Copy link

Description

Removes an unnecessary sleep from test_waitable.cpp.

The test contained a TODO comment questioning the purpose of a std::this_thread::sleep_for(3ms) call. The sleep has been removed to simplify the test and avoid unnecessary delays.

Is this user-facing behavior change?

No.

Did you use Generative AI?

No.

Additional Information

This change is limited to test code and should not affect runtime behavior.

Note: A local build was attempted but failed due to a version mismatch between the rclcpp source and the installed ROS rolling binaries. CI should validate this change in the correct environment.

Signed-off-by: Anusha Sharma <anushasharma.wa@gmail.com>
@Anusha-Sharma-2
Copy link
Author

It looks like the build is failing due to a missing symbol (rcl_subscription_is_cft_supported) in subscription_base.cpp, which appears unrelated to this change.

I encountered the same error locally, so I’m wondering if this might be due to a version mismatch between rclcpp and rcl.

Since this PR only modifies a test file, I don’t expect it to affect compilation. Happy to investigate further or adjust if needed.

// not be there, or test cases where that is important should use the
// on_execute_callback?
std::this_thread::sleep_for(3ms);
// Removed unnecessary sleep based on TODO comment; tests should rely on explicit synchronization instead
Copy link
Collaborator

Choose a reason for hiding this comment

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

then why do we not remove the else statement?

Comment on lines -82 to -85
// TODO(wjwwood): I don't know why this was here, but probably it should
// not be there, or test cases where that is important should use the
// on_execute_callback?
std::this_thread::sleep_for(3ms);
Copy link
Collaborator

Choose a reason for hiding this comment

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

do you have any rational reason that we can remove this sleep instead of being said by this comment? the comment here looks pretty old, and code base could be really different as it grows. i do not think relying only on the comment would be good enough to modify and change the behavior?

Signed-off-by: Anusha Sharma <anushasharma.wa@gmail.com>
@Anusha-Sharma-2 Anusha-Sharma-2 force-pushed the fix-test-waitable-sleep branch from d4074c4 to 2715400 Compare March 26, 2026 01:30
@Anusha-Sharma-2
Copy link
Author

Thanks for pointing that out!

I’ve updated the implementation to remove the else branch as well.

Regarding the sleep_for, I took a closer look across the codebase to identify a reason for its use in this file. In most cases, 'sleep_for' is tied to:

  • waiting for asynchronous events (timers, futures),
  • polling loops with a condition,
  • or explicitly documented synchronization needs.

In test_waitable, the sleep appears in a fallback branch and is not associated with any condition or observable behavior, which makes its role unclear from the current context.

If the sleep was originally introduced to mitigate a timing or race-related issue, it might be worth identifying and documenting that explicitly rather than relying on an unconditional delay, and I'd love to help identify that.

That said, I may be missing some historical context here, so I’m happy to keep or adjust the approach if this sleep is still required for test stability.

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