diff --git a/diagnostic_updater/include/diagnostic_updater/diagnostic_updater.hpp b/diagnostic_updater/include/diagnostic_updater/diagnostic_updater.hpp index a301ada59..2ecb08ab1 100644 --- a/diagnostic_updater/include/diagnostic_updater/diagnostic_updater.hpp +++ b/diagnostic_updater/include/diagnostic_updater/diagnostic_updater.hpp @@ -511,7 +511,7 @@ class Updater : public DiagnosticTaskVector */ void update() { - if (rclcpp::ok()) { + if (rclcpp::ok(base_interface_->get_context())) { bool warn_nohwid = hwid_.empty(); std::vector status_vec; diff --git a/diagnostic_updater/test/diagnostic_updater_test.cpp b/diagnostic_updater/test/diagnostic_updater_test.cpp index 0362b2897..6fd7d1998 100644 --- a/diagnostic_updater/test/diagnostic_updater_test.cpp +++ b/diagnostic_updater/test/diagnostic_updater_test.cpp @@ -134,6 +134,42 @@ TEST(DiagnosticUpdater, testUpdaterAsNodeClassMember) { SUCCEED(); } +class SaveIfCalled : public diagnostic_updater::DiagnosticTask +{ +public: + SaveIfCalled() + : DiagnosticTask("SaveIfCalled") {} + + void run(diagnostic_updater::DiagnosticStatusWrapper & s) + { + s.summary(0, "Have been called!"); + has_been_called_ = true; + } + + bool has_been_called() const + { + return has_been_called_; + } + +private: + bool has_been_called_ = false; +}; + + +TEST(DiagnosticUpdater, testCustomContext) { + auto context = std::make_shared(); + context->init(0, nullptr, rclcpp::InitOptions()); + + auto node = + std::make_shared("CustomContextNode", rclcpp::NodeOptions().context(context)); + diagnostic_updater::Updater updater(node); + SaveIfCalled save_if_called; + updater.add(save_if_called); + updater.force_update(); + ASSERT_TRUE(save_if_called.has_been_called()); + context->shutdown("End test"); +} + TEST(DiagnosticUpdater, testDiagnosticStatusWrapperKeyValuePairs) { diagnostic_updater::DiagnosticStatusWrapper stat;