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

Fixup Executor::spin_all() regression fix #2517

Merged
merged 9 commits into from
May 2, 2024
Prev Previous commit
Next Next commit
restore previous test logic for now
Signed-off-by: William Woodall <william@osrfoundation.org>
wjwwood committed Apr 30, 2024
commit 500ee7d76dc6e76e8e52c5744a6743f4e0367fd5
34 changes: 27 additions & 7 deletions rclcpp/test/rclcpp/executors/test_executors.cpp
Original file line number Diff line number Diff line change
@@ -447,17 +447,37 @@ TYPED_TEST(TestExecutors, spinAll)
waitable_interfaces->add_waitable(my_waitable, nullptr);
executor.add_node(this->node);

// trigger multiple times, so that some work is available
my_waitable->trigger();
my_waitable->trigger();
my_waitable->trigger();
// Long timeout, but should not block test if spin_all works as expected as we cancel the
// executor.
bool spin_exited = false;
std::thread spinner([&spin_exited, &executor, this]() {
executor.spin_all(1s);
executor.remove_node(this->node, true);
spin_exited = true;
});

// Long timeout, but should not block as almost no work is available
executor.spin_all(1s);
executor.remove_node(this->node, true);
// Do some work until sufficient calls to the waitable occur
auto start = std::chrono::steady_clock::now();
while (
my_waitable->get_count() <= 1 &&
!spin_exited &&
(std::chrono::steady_clock::now() - start < 1s))
{
my_waitable->trigger();
this->publisher->publish(test_msgs::msg::Empty());
std::this_thread::sleep_for(1ms);
}

executor.cancel();
start = std::chrono::steady_clock::now();
while (!spin_exited && (std::chrono::steady_clock::now() - start) < 1s) {
std::this_thread::sleep_for(1ms);
}

EXPECT_LT(1u, my_waitable->get_count());
waitable_interfaces->remove_waitable(my_waitable, nullptr);
ASSERT_TRUE(spin_exited);
spinner.join();
}

// Helper function to convert chrono durations into a scalar that GoogleTest