Skip to content

Commit

Permalink
add 30 seconds timeout to each while loop
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Soragna <[email protected]>
  • Loading branch information
alsora committed Mar 28, 2024
1 parent f2869e0 commit e06bd91
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion rclcpp/test/rclcpp/test_timers_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,13 @@ TEST_F(TestTimersManager, check_one_timer_cancel_doesnt_affect_other_timers)
timers_manager->start();

// Wait for t1 to be canceled
auto loop_start_time = std::chrono::high_resolution_clock::now();
while (!t1->is_canceled()) {
auto now = std::chrono::high_resolution_clock::now();
if (now - loop_start_time >= std::chrono::seconds(30)) {
FAIL() << "timeout waiting for t1 to be canceled";
break;
}
std::this_thread::sleep_for(3ms);
}

Expand All @@ -410,10 +416,16 @@ TEST_F(TestTimersManager, check_one_timer_cancel_doesnt_affect_other_timers)
// Verify that t2 is still being invoked
const size_t start_t2_runs = t2_runs;
const size_t num_t2_extra_runs = 6;
loop_start_time = std::chrono::high_resolution_clock::now();
while (t2_runs < start_t2_runs + num_t2_extra_runs) {
auto now = std::chrono::high_resolution_clock::now();
if (now - loop_start_time >= std::chrono::seconds(30)) {
FAIL() << "timeout waiting for t2 to do some runs";
break;
}
std::this_thread::sleep_for(3ms);
}

EXPECT_TRUE(t1->is_canceled());
EXPECT_FALSE(t2->is_canceled());
// t1 hasn't run since before
Expand Down

0 comments on commit e06bd91

Please sign in to comment.