diff options
author | Nick Vatamaniuc <vatamane@apache.org> | 2021-10-24 22:35:01 -0400 |
---|---|---|
committer | Nick Vatamaniuc <nickva@users.noreply.github.com> | 2021-10-24 23:30:58 -0400 |
commit | 56f4817f62189ca599ba54b106be6bb5316453f9 (patch) | |
tree | d8c003f598b483dec9852c61c322d3c7038c96cc | |
parent | c1bb4e4856edd93255d75ebe158b4da38bbf3333 (diff) | |
download | couchdb-56f4817f62189ca599ba54b106be6bb5316453f9.tar.gz |
Fix flaky retain_stats replicator test
Noticed this flaky test show up in a few recent test runs, for
[example](https://ci-couchdb.apache.org/blue/organizations/jenkins/jenkins-cm1%2FPullRequests/detail/PR-3799/1/pipeline)
The test was flaky as We were only waiting for the replication task or
scheduler job to appear in the list but didn't not wait until the
value of the task had been updated to an expected value. So the task
might have appeared but then only half the docs written (say, 5
instead of 10). Testing the value at that stage is too early and the
test would fail.
To fix the issue, besides waiting on the task/job to appear in the
list, also wait until its `docs_written` value matches the expected
value. By that point `docs_read` should have caught up as well.
-rw-r--r-- | src/couch_replicator/test/eunit/couch_replicator_retain_stats_between_job_runs.erl | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/couch_replicator/test/eunit/couch_replicator_retain_stats_between_job_runs.erl b/src/couch_replicator/test/eunit/couch_replicator_retain_stats_between_job_runs.erl index 037f37191..a9a0fc943 100644 --- a/src/couch_replicator/test/eunit/couch_replicator_retain_stats_between_job_runs.erl +++ b/src/couch_replicator/test/eunit/couch_replicator_retain_stats_between_job_runs.erl @@ -138,7 +138,7 @@ start_job() -> check_active_tasks(DocsRead, DocsWritten, DocsFailed) -> - RepTask = wait_for_task_status(), + RepTask = wait_for_task_status(DocsWritten), ?assertNotEqual(timeout, RepTask), ?assertEqual(DocsRead, couch_util:get_value(docs_read, RepTask)), ?assertEqual(DocsWritten, couch_util:get_value(docs_written, RepTask)), @@ -147,7 +147,7 @@ check_active_tasks(DocsRead, DocsWritten, DocsFailed) -> check_scheduler_jobs(DocsRead, DocsWritten, DocFailed) -> - Info = wait_scheduler_info(), + Info = wait_scheduler_info(DocsWritten), ?assert(maps:is_key(<<"changes_pending">>, Info)), ?assert(maps:is_key(<<"doc_write_failures">>, Info)), ?assert(maps:is_key(<<"docs_read">>, Info)), @@ -167,21 +167,29 @@ replication_tasks() -> end, couch_task_status:all()). -wait_for_task_status() -> +wait_for_task_status(DocsWritten) -> test_util:wait(fun() -> case replication_tasks() of [] -> wait; - [RepTask] -> RepTask + [RepTask] -> + case couch_util:get_value(docs_written, RepTask) of + DocsWritten -> RepTask; + _Other -> wait + end end end). -wait_scheduler_info() -> +wait_scheduler_info(DocsWritten) -> test_util:wait(fun() -> case scheduler_jobs() of [] -> wait; [#{<<"info">> := null}] -> wait; - [#{<<"info">> := Info}] -> Info + [#{<<"info">> := Info}] -> + case maps:get(<<"docs_written">>, Info, undefined) of + DocsWritten -> Info; + _Other -> wait + end end end). |