Skip to content

Commit e06bd91

Browse files
committed
add 30 seconds timeout to each while loop
Signed-off-by: Alberto Soragna <[email protected]>
1 parent f2869e0 commit e06bd91

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

rclcpp/test/rclcpp/test_timers_manager.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,13 @@ TEST_F(TestTimersManager, check_one_timer_cancel_doesnt_affect_other_timers)
399399
timers_manager->start();
400400

401401
// Wait for t1 to be canceled
402+
auto loop_start_time = std::chrono::high_resolution_clock::now();
402403
while (!t1->is_canceled()) {
404+
auto now = std::chrono::high_resolution_clock::now();
405+
if (now - loop_start_time >= std::chrono::seconds(30)) {
406+
FAIL() << "timeout waiting for t1 to be canceled";
407+
break;
408+
}
403409
std::this_thread::sleep_for(3ms);
404410
}
405411

@@ -410,10 +416,16 @@ TEST_F(TestTimersManager, check_one_timer_cancel_doesnt_affect_other_timers)
410416
// Verify that t2 is still being invoked
411417
const size_t start_t2_runs = t2_runs;
412418
const size_t num_t2_extra_runs = 6;
419+
loop_start_time = std::chrono::high_resolution_clock::now();
413420
while (t2_runs < start_t2_runs + num_t2_extra_runs) {
421+
auto now = std::chrono::high_resolution_clock::now();
422+
if (now - loop_start_time >= std::chrono::seconds(30)) {
423+
FAIL() << "timeout waiting for t2 to do some runs";
424+
break;
425+
}
414426
std::this_thread::sleep_for(3ms);
415427
}
416-
428+
417429
EXPECT_TRUE(t1->is_canceled());
418430
EXPECT_FALSE(t2->is_canceled());
419431
// t1 hasn't run since before

0 commit comments

Comments
 (0)