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 02:40:00 UTC

[couchdb] branch fix-flaky-replicator-stats-test created (now 5468c44)

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

vatamane pushed a change to branch fix-flaky-replicator-stats-test
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


      at 5468c44  Fix flaky retain_stats replicator test

This branch includes the following new commits:

     new 5468c44  Fix flaky retain_stats replicator test

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[couchdb] 01/01: Fix flaky retain_stats replicator test

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch fix-flaky-replicator-stats-test
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 5468c44951d0b5a486b57f62ce106dc129346941
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.
    
    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 (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
    the 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).