@@ -86,6 +86,8 @@ TEST(SimpleChargingDockTests, BatteryState)
86
86
87
87
dock->configure (node, " my_dock" , nullptr );
88
88
dock->activate ();
89
+ rclcpp::executors::SingleThreadedExecutor executor;
90
+ executor.add_node (node->get_node_base_interface ());
89
91
geometry_msgs::msg::PoseStamped pose;
90
92
EXPECT_TRUE (dock->getRefinedPose (pose, " " ));
91
93
@@ -95,7 +97,7 @@ TEST(SimpleChargingDockTests, BatteryState)
95
97
pub->publish (msg);
96
98
rclcpp::Rate r (2 );
97
99
r.sleep ();
98
- rclcpp:: spin_some (node-> get_node_base_interface () );
100
+ executor. spin_some ();
99
101
100
102
EXPECT_FALSE (dock->isCharging ());
101
103
EXPECT_TRUE (dock->hasStoppedCharging ());
@@ -106,7 +108,7 @@ TEST(SimpleChargingDockTests, BatteryState)
106
108
pub->publish (msg2);
107
109
rclcpp::Rate r1 (2 );
108
110
r1.sleep ();
109
- rclcpp:: spin_some (node-> get_node_base_interface () );
111
+ executor. spin_some ();
110
112
111
113
EXPECT_TRUE (dock->isCharging ());
112
114
EXPECT_FALSE (dock->hasStoppedCharging ());
@@ -139,6 +141,8 @@ TEST(SimpleChargingDockTests, StallDetection)
139
141
rclcpp::Parameter (" my_dock.stall_joint_names" , rclcpp::ParameterValue (names)));
140
142
dock->configure (node, " my_dock" , nullptr );
141
143
dock->activate ();
144
+ rclcpp::executors::SingleThreadedExecutor executor;
145
+ executor.add_node (node->get_node_base_interface ());
142
146
EXPECT_EQ (dock->getStallJointNames (), names);
143
147
144
148
// Stopped, but below effort threshold
@@ -149,7 +153,7 @@ TEST(SimpleChargingDockTests, StallDetection)
149
153
pub->publish (msg);
150
154
rclcpp::Rate r (2 );
151
155
r.sleep ();
152
- rclcpp:: spin_some (node-> get_node_base_interface () );
156
+ executor. spin_some ();
153
157
154
158
EXPECT_FALSE (dock->isDocked ());
155
159
@@ -161,7 +165,7 @@ TEST(SimpleChargingDockTests, StallDetection)
161
165
pub->publish (msg2);
162
166
rclcpp::Rate r1 (2 );
163
167
r1.sleep ();
164
- rclcpp:: spin_some (node-> get_node_base_interface () );
168
+ executor. spin_some ();
165
169
166
170
EXPECT_FALSE (dock->isDocked ());
167
171
@@ -173,7 +177,7 @@ TEST(SimpleChargingDockTests, StallDetection)
173
177
pub->publish (msg3);
174
178
rclcpp::Rate r2 (2 );
175
179
r2.sleep ();
176
- rclcpp:: spin_some (node-> get_node_base_interface () );
180
+ executor. spin_some ();
177
181
178
182
EXPECT_TRUE (dock->isDocked ());
179
183
@@ -245,6 +249,8 @@ TEST(SimpleChargingDockTests, RefinedPoseTest)
245
249
dock->configure (node, " my_dock" , nullptr );
246
250
dock->activate ();
247
251
dock->startDetectionProcess ();
252
+ rclcpp::executors::SingleThreadedExecutor executor;
253
+ executor.add_node (node->get_node_base_interface ());
248
254
249
255
geometry_msgs::msg::PoseStamped pose;
250
256
@@ -258,7 +264,7 @@ TEST(SimpleChargingDockTests, RefinedPoseTest)
258
264
detected_pose.pose .position .x = 0.1 ;
259
265
detected_pose.pose .position .y = -0.5 ;
260
266
pub->publish (detected_pose);
261
- rclcpp:: spin_some (node-> get_node_base_interface () );
267
+ executor. spin_some ();
262
268
std::this_thread::sleep_for (std::chrono::milliseconds (100 ));
263
269
264
270
pose.header .frame_id = " my_frame" ;
@@ -287,14 +293,16 @@ TEST(SimpleChargingDockTests, RefinedPoseNotTransform)
287
293
288
294
dock->configure (node, " my_dock" , tf_buffer);
289
295
dock->activate ();
296
+ rclcpp::executors::SingleThreadedExecutor executor;
297
+ executor.add_node (node->get_node_base_interface ());
290
298
291
299
geometry_msgs::msg::PoseStamped detected_pose;
292
300
detected_pose.header .stamp = node->now ();
293
301
detected_pose.header .frame_id = " my_frame" ;
294
302
detected_pose.pose .position .x = 1.0 ;
295
303
detected_pose.pose .position .y = 1.0 ;
296
304
pub->publish (detected_pose);
297
- rclcpp:: spin_some (node-> get_node_base_interface () );
305
+ executor. spin_some ();
298
306
299
307
// Create a pose with a different frame_id
300
308
geometry_msgs::msg::PoseStamped pose;
@@ -325,6 +333,8 @@ TEST(SimpleChargingDockTests, IsDockedTransformException)
325
333
dock->configure (node, " my_dock" , tf_buffer);
326
334
dock->activate ();
327
335
dock->startDetectionProcess ();
336
+ rclcpp::executors::SingleThreadedExecutor executor;
337
+ executor.add_node (node->get_node_base_interface ());
328
338
329
339
// Create a pose with a different frame_id
330
340
geometry_msgs::msg::PoseStamped pose;
@@ -347,7 +357,7 @@ TEST(SimpleChargingDockTests, IsDockedTransformException)
347
357
detected_pose.pose .position .x = 1.0 ;
348
358
detected_pose.pose .position .y = 1.0 ;
349
359
pub->publish (detected_pose);
350
- rclcpp:: spin_some (node-> get_node_base_interface () );
360
+ executor. spin_some ();
351
361
352
362
// Second call should succeed
353
363
EXPECT_TRUE (dock->getRefinedPose (pose, " " ));
@@ -452,12 +462,14 @@ TEST(SimpleChargingDockTests, DetectorLifecycle)
452
462
453
463
dock->activate ();
454
464
dock->startDetectionProcess ();
465
+ rclcpp::executors::SingleThreadedExecutor executor;
466
+ executor.add_node (node->get_node_base_interface ());
455
467
// Spin to process async service call
456
468
auto start_time = std::chrono::steady_clock::now ();
457
469
while (!service_called &&
458
470
std::chrono::steady_clock::now () - start_time < std::chrono::seconds (2 ))
459
471
{
460
- rclcpp:: spin_some (node-> get_node_base_interface () );
472
+ executor. spin_some ();
461
473
std::this_thread::sleep_for (std::chrono::milliseconds (10 ));
462
474
}
463
475
EXPECT_TRUE (service_called);
@@ -502,19 +514,21 @@ TEST(SimpleChargingDockTests, SubscriptionCallback)
502
514
publisher->on_activate ();
503
515
504
516
dock->startDetectionProcess ();
517
+ rclcpp::executors::SingleThreadedExecutor executor;
518
+ executor.add_node (node->get_node_base_interface ());
505
519
506
520
// Wait for the publisher and subscriber to connect.
507
521
int tries = 0 ;
508
522
while (publisher->get_subscription_count () == 0 && tries++ < 10 ) {
509
- rclcpp:: spin_some (node-> get_node_base_interface () );
523
+ executor. spin_some ();
510
524
std::this_thread::sleep_for (100ms);
511
525
}
512
526
ASSERT_GT (publisher->get_subscription_count (), 0 );
513
527
514
528
// Publish a message to trigger the subscription callback.
515
529
publisher->publish (geometry_msgs::msg::PoseStamped{});
516
530
std::this_thread::sleep_for (50ms);
517
- rclcpp:: spin_some (node-> get_node_base_interface () );
531
+ executor. spin_some ();
518
532
519
533
// Verify the detector state was updated, proving the callback was executed.
520
534
EXPECT_TRUE (dock->isDetectorActive ());
@@ -608,17 +622,18 @@ TEST(SimpleChargingDockTests, SubscriptionPersistent)
608
622
auto publisher = node->create_publisher <geometry_msgs::msg::PoseStamped>(
609
623
" detected_dock_pose" , rclcpp::QoS (1 ));
610
624
publisher->on_activate ();
611
-
625
+ rclcpp::executors::SingleThreadedExecutor executor;
626
+ executor.add_node (node->get_node_base_interface ());
612
627
int tries = 0 ;
613
628
while (publisher->get_subscription_count () == 0 && tries++ < 10 ) {
614
- rclcpp:: spin_some (node-> get_node_base_interface () );
629
+ executor. spin_some ();
615
630
std::this_thread::sleep_for (100ms);
616
631
}
617
632
ASSERT_GT (publisher->get_subscription_count (), 0 );
618
633
619
634
publisher->publish (geometry_msgs::msg::PoseStamped{});
620
635
std::this_thread::sleep_for (50ms);
621
- rclcpp:: spin_some (node-> get_node_base_interface () );
636
+ executor. spin_some ();
622
637
623
638
// Verify the detector state changed, proving the callback was executed.
624
639
EXPECT_TRUE (dock->isDetectorActive ());
0 commit comments