@@ -71,6 +71,8 @@ class TestTopicToolSingleSub : public TestTopicTool
7171 const std::string test_name =
7272 ::testing::UnitTest::GetInstance ()->current_test_info()->name();
7373 test_node_ = rclcpp::Node::make_shared (test_name);
74+ executor_ = std::make_shared<rclcpp::executors::SingleThreadedExecutor>();
75+ executor_->add_node (test_node_);
7476 target_input_topic_ = " /" + test_name + " /input" ;
7577 target_output_topic_ = " /" + test_name + " /output" ;
7678 subscription_ = test_node_->create_subscription <std_msgs::msg::String>(
@@ -94,8 +96,8 @@ class TestTopicToolSingleSub : public TestTopicTool
9496 auto message = std_msgs::msg::String ();
9597 message.data = msg_content;
9698 publisher_->publish (message);
97- rclcpp::spin_some (target_node );
98- rclcpp:: spin_some (test_node_ );
99+ executor_-> spin_node_all (target_node, std::chrono::nanoseconds ( 0 ) );
100+ executor_-> spin_some ();
99101 }
100102
101103 std::string get_target_input_topic ()
@@ -112,6 +114,7 @@ class TestTopicToolSingleSub : public TestTopicTool
112114 std::shared_ptr<rclcpp::Node> test_node_;
113115 rclcpp::Subscription<std_msgs::msg::String>::SharedPtr subscription_;
114116 rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_;
117+ std::shared_ptr<rclcpp::executors::SingleThreadedExecutor> executor_;
115118 std::string target_input_topic_;
116119 std::string target_output_topic_;
117120};
@@ -125,6 +128,8 @@ class TestTopicToolMultiSub : public TestTopicTool
125128 const std::string test_name =
126129 ::testing::UnitTest::GetInstance ()->current_test_info()->name();
127130 test_node_ = rclcpp::Node::make_shared (test_name);
131+ executor_ = std::make_shared<rclcpp::executors::SingleThreadedExecutor>();
132+ executor_->add_node (test_node_);
128133 target_input_topic_prefix_ = " /" + test_name + " /input" ;
129134 target_output_topic_ = " /" + test_name + " /output" ;
130135 subscription_ = test_node_->create_subscription <std_msgs::msg::String>(
@@ -155,8 +160,8 @@ class TestTopicToolMultiSub : public TestTopicTool
155160 message.data = msg_content;
156161 assert (publisher_index < num_target_input_topics_);
157162 publishers_[publisher_index]->publish (message);
158- rclcpp::spin_some (target_node );
159- rclcpp:: spin_some (test_node_ );
163+ executor_-> spin_node_all (target_node, std::chrono::nanoseconds ( 0 ) );
164+ executor_-> spin_some ();
160165 }
161166
162167 std::vector<std::string> get_target_input_topics ()
@@ -175,6 +180,7 @@ class TestTopicToolMultiSub : public TestTopicTool
175180
176181protected:
177182 std::shared_ptr<rclcpp::Node> test_node_;
183+ std::shared_ptr<rclcpp::executors::SingleThreadedExecutor> executor_;
178184
179185private:
180186 rclcpp::Subscription<std_msgs::msg::String>::SharedPtr subscription_;
@@ -193,6 +199,8 @@ class TestTopicToolMultiPub : public TestTopicTool
193199 using std::placeholders::_1;
194200 const std::string test_name = ::testing::UnitTest::GetInstance ()->current_test_info ()->name ();
195201 test_node_ = rclcpp::Node::make_shared (test_name);
202+ executor_ = std::make_shared<rclcpp::executors::SingleThreadedExecutor>();
203+ executor_->add_node (test_node_);
196204 target_input_topic_ = " /" + test_name + " /input" ;
197205 target_output_topic_prefix_ = " /" + test_name + " /output" ;
198206 publisher_ = test_node_->create_publisher <std_msgs::msg::String>(target_input_topic_, 10 );
@@ -219,8 +227,8 @@ class TestTopicToolMultiPub : public TestTopicTool
219227 auto message = std_msgs::msg::String ();
220228 message.data = msg_content;
221229 publisher_->publish (message);
222- rclcpp::spin_some (target_node );
223- rclcpp:: spin_some (test_node_ );
230+ executor_-> spin_node_all (target_node, std::chrono::nanoseconds ( 0 ) );
231+ executor_-> spin_some ();
224232 }
225233
226234 std::vector<std::string> get_target_output_topics ()
@@ -236,6 +244,7 @@ class TestTopicToolMultiPub : public TestTopicTool
236244
237245protected:
238246 std::shared_ptr<rclcpp::Node> test_node_;
247+ std::shared_ptr<rclcpp::executors::SingleThreadedExecutor> executor_;
239248
240249private:
241250 rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_;
0 commit comments