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

Make test_two_timers_ready_before_timeout less flaky #911

Merged
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
46 changes: 33 additions & 13 deletions rcl/test/rcl/test_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,24 @@ TEST_F(TestTimerFixture, test_two_timers) {
ret = rcl_wait_set_fini(&wait_set);
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
});
ret = rcl_wait(&wait_set, RCL_MS_TO_NS(100));
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
// The loop is needed because the rcl_wait_set might suffer spurious
// awakes when timers are involved.
// The loop can be removed if spurious awakes are fixed in the future.
// This issue particularly happens on Windows.
uint8_t nonnull_timers = 0;
for (uint8_t i = 0; i < wait_set.size_of_timers; i++) {
if (wait_set.timers[i] != NULL) {
nonnull_timers++;
auto start = std::chrono::system_clock::now();
do {
ret = rcl_wait(&wait_set, RCL_MS_TO_NS(100));
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
for (uint8_t i = 0; i < wait_set.size_of_timers; i++) {
if (wait_set.timers[i] != NULL) {
nonnull_timers++;
}
}
}
} while (
nonnull_timers == 0u ||
std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now() - start).count() > 100u);
bool is_ready = false;
ret = rcl_timer_is_ready(&timer, &is_ready);
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
Expand Down Expand Up @@ -304,14 +314,24 @@ TEST_F(TestTimerFixture, test_two_timers_ready_before_timeout) {
ret = rcl_wait_set_fini(&wait_set);
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
});
ret = rcl_wait(&wait_set, RCL_MS_TO_NS(100));
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
uint8_t nonnull_timers = 0;
for (uint8_t i = 0; i < wait_set.size_of_timers; i++) {
if (wait_set.timers[i] != NULL) {
nonnull_timers++;
// The loop is needed because the rcl_wait_set might suffer spurious
// awakes when timers are involved.
// The loop can be removed if spurious awakes are fixed in the future.
// This issue particularly happens on Windows.
uint8_t nonnull_timers = 0u;
auto start = std::chrono::system_clock::now();
do {
ret = rcl_wait(&wait_set, RCL_MS_TO_NS(100));
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
for (uint8_t i = 0; i < wait_set.size_of_timers; i++) {
if (wait_set.timers[i] != NULL) {
nonnull_timers++;
}
}
}
} while (
nonnull_timers == 0u ||
std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now() - start).count() > 100u);
ivanpauno marked this conversation as resolved.
Show resolved Hide resolved
bool is_ready = false;
ret = rcl_timer_is_ready(&timer, &is_ready);
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
Expand Down