Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initialize the global context to avoid runtime_error upon destruction #128

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions test/realtime_clock_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,24 @@ using realtime_tools::RealtimeClock;

TEST(RealtimeClock, get_system_time)
{
// initialize the global context
rclcpp::init(0, nullptr);
const int ATTEMPTS = 10;
const std::chrono::milliseconds DELAY(1);

rclcpp::Clock::SharedPtr clock(new rclcpp::Clock());
RealtimeClock rt_clock(clock);
// Wait for time to be available
rclcpp::Time last_rt_time;
for (int i = 0; i < ATTEMPTS && rclcpp::Time() == last_rt_time; ++i) {
std::this_thread::sleep_for(DELAY);
last_rt_time = rt_clock.now(rclcpp::Time());
}
ASSERT_NE(rclcpp::Time(), last_rt_time);
{
RealtimeClock rt_clock(clock);
// Wait for time to be available
rclcpp::Time last_rt_time;
for (int i = 0; i < ATTEMPTS && rclcpp::Time() == last_rt_time; ++i) {
std::this_thread::sleep_for(DELAY);
last_rt_time = rt_clock.now(rclcpp::Time());
}
ASSERT_NE(rclcpp::Time(), last_rt_time);

// This test assumes system time will not jump backwards during it
EXPECT_GT(rt_clock.now(last_rt_time), last_rt_time);
// This test assumes system time will not jump backwards during it
EXPECT_GT(rt_clock.now(last_rt_time), last_rt_time);
}
rclcpp::shutdown();
}
Loading