Skip to content

Commit 27402a4

Browse files
jameseh96daverigby
authored andcommitted
MB-43238: Fix intermittent failure of expiry pager settings test
The test checks that the expected run time of the expiry pager task is within an upper and lower bound based on the time before/after setting the config param, plus the sleep time. This ensures the test is resilient to time passing between computing an expected time and the config actually being applied. However, the test relies on system_clock, whereas the expiry pager config derives the current time using ep_current_time(), which is subject to memcached_uptime ticks. The time computed by the expiry pager can then appear to be (at most) one second behind system_clock, dependent on exactly when the time was determined relative to when the tick occurs. Fix by relaxing the test checks by one second. A better fix might be to settle on one time source for the test and pager for consistency, but relaxing the test is a less invasive path to resolving the intermittent failure. Change-Id: I53efc937f07a48ce1d3b2157ec3aea31efe93b38 Reviewed-on: http://review.couchbase.org/c/kv_engine/+/163884 Tested-by: Build Bot <[email protected]> Reviewed-by: Richard de Mellow <[email protected]> Reviewed-by: Dave Rigby <[email protected]>
1 parent c780b50 commit 27402a4

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

engines/ep/tests/ep_testsuite.cc

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,9 @@ static enum test_result test_expiry_pager_settings(EngineIface* h) {
643643
get_int_stat(h, "ep_exp_pager_stime"),
644644
"Expiry pager sleep time not updated");
645645
cb_assert(!get_bool_stat(h, "ep_exp_pager_enabled"));
646-
std::this_thread::sleep_for(std::chrono::seconds(1));
646+
using namespace std::chrono;
647+
using namespace std::chrono_literals;
648+
std::this_thread::sleep_for(1s);
647649
checkeq(0,
648650
get_int_stat(h, "ep_num_expiry_pager_runs"),
649651
"Expiry pager run count is not zero");
@@ -687,23 +689,27 @@ static enum test_result test_expiry_pager_settings(EngineIface* h) {
687689
checkeq(0, str.substr(11, 5).compare(expected_time), err_msg.c_str());
688690

689691
// Update exp_pager_stime by 30 minutes and ensure that the update is successful
690-
const std::chrono::minutes update_by{30};
691-
std::string targetTaskTime1{make_time_string(std::chrono::system_clock::now() +
692-
update_by)};
692+
const auto update_by = 30min;
693+
// the calculated task time depends on memcached_uptime ticks, so can be
694+
// at most 1 second behind based on exactly when it is checked;
695+
// reduce the lower bound to allow this.
696+
std::string targetTaskTime1{
697+
make_time_string(system_clock::now() + update_by - 1s)};
693698

694699
// clear the initial task time, and test setting stime results in an exact
695700
// result of
696701
// task_time = now + stime
697702
set_param(
698703
h, EngineParamCategory::Flush, "exp_pager_initial_run_time", "-1");
699-
set_param(h,
700-
EngineParamCategory::Flush,
701-
"exp_pager_stime",
702-
std::to_string(update_by.count() * 60).c_str());
704+
set_param(
705+
h,
706+
EngineParamCategory::Flush,
707+
"exp_pager_stime",
708+
std::to_string(duration_cast<seconds>(update_by).count()).c_str());
703709
str = get_str_stat(h, "ep_expiry_pager_task_time");
704710

705-
std::string targetTaskTime2{make_time_string(std::chrono::system_clock::now() +
706-
update_by)};
711+
std::string targetTaskTime2{
712+
make_time_string(system_clock::now() + update_by)};
707713

708714
// ep_expiry_pager_task_time should fall within the range of
709715
// targetTaskTime1 and targetTaskTime2

0 commit comments

Comments
 (0)