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

Make test_executor.spin_some_max_duration more reliable #430

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions test_rclcpp/test/test_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TEST(CLASSNAME(test_executor, RMW_IMPLEMENTATION), spin_some_max_duration) {
rclcpp::executors::SingleThreadedExecutor executor;
auto node = rclcpp::Node::make_shared("spin_some_max_duration");
auto lambda = []() {
std::this_thread::sleep_for(1ms);
std::this_thread::sleep_for(100ms);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good change, and keeps the current semantics of the test; basically, that 20 threads of N ms sleep take < 20*N ms to complete. However, those semantics are a bit hard to discern here. Would you mind adding a comment explaining that?

Copy link
Member Author

Choose a reason for hiding this comment

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

There was already a comment, but I forgot to update it.
See 2d0e91c.

};
std::vector<std::shared_ptr<rclcpp::WallTimer<decltype(lambda)>>> timers;
// creating 20 timers which will try to do 1 ms of work each
Expand All @@ -72,12 +72,12 @@ TEST(CLASSNAME(test_executor, RMW_IMPLEMENTATION), spin_some_max_duration) {
}
executor.add_node(node);

const auto max_duration = 10ms;
const auto max_duration = 1s;
const auto start = std::chrono::steady_clock::now();
executor.spin_some(max_duration);
const auto end = std::chrono::steady_clock::now();
ASSERT_LT(max_duration, end - start);
ASSERT_GT(max_duration + 5ms, end - start);
ASSERT_GT(max_duration + 100ms, end - start);
}

TEST(CLASSNAME(test_executor, RMW_IMPLEMENTATION), multithreaded_spin_call) {
Expand Down