You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2021/10/25 03:31:05 UTC

[couchdb] branch 3.x updated: Fix flaky retain_stats replicator test

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch 3.x
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/3.x by this push:
     new 56f4817  Fix flaky retain_stats replicator test
56f4817 is described below

commit 56f4817f62189ca599ba54b106be6bb5316453f9
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Sun Oct 24 22:35:01 2021 -0400

    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.
---
 ...ouch_replicator_retain_stats_between_job_runs.erl | 20 ++++++++++++++------
 1 file 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 037f371..a9a0fc9 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).