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 2023/02/14 04:40:48 UTC

[couchdb] 01/01: Test the update_docs=true case in replicator scheduler docs test

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

vatamane pushed a commit to branch fix-replicator-scheduler-doc-tests-for-update-docs-true
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 48cba0eeb51e765bca7d8a4783595d80f132f39f
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Mon Feb 13 23:32:52 2023 -0500

    Test the update_docs=true case in replicator scheduler docs test
    
    For completeness, make sure to test replicator doc updates with
    `update_docs=true` setting as well.
    
    Issue: https://github.com/apache/couchdb/pull/4423
---
 .../couch_replicator_scheduler_docs_tests.erl      | 27 +++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/src/couch_replicator/test/eunit/couch_replicator_scheduler_docs_tests.erl b/src/couch_replicator/test/eunit/couch_replicator_scheduler_docs_tests.erl
index 10a48d08e..192d113c6 100644
--- a/src/couch_replicator/test/eunit/couch_replicator_scheduler_docs_tests.erl
+++ b/src/couch_replicator/test/eunit/couch_replicator_scheduler_docs_tests.erl
@@ -40,8 +40,15 @@ setup_prefixed_replicator_db() ->
     RepDb = setup_replicator_db(?tempdb()),
     {Ctx, {RepDb, Source, Target}}.
 
+setup_prefixed_replicator_db_with_update_docs_true() ->
+    {Ctx, {Source, Target}} = couch_replicator_test_helper:test_setup(),
+    config:set("replicator", "update_docs", "true", _Persist = false),
+    RepDb = setup_replicator_db(?tempdb()),
+    {Ctx, {RepDb, Source, Target}}.
+
 teardown({Ctx, {RepDb, Source, Target}}) ->
     ok = fabric:delete_db(RepDb, [?ADMIN_CTX]),
+    config:delete("replicator", "update_docs", _Persist = false),
     couch_replicator_test_helper:test_teardown({Ctx, {Source, Target}}).
 
 scheduler_docs_test_main_db_test_() ->
@@ -99,6 +106,17 @@ t_replicator_doc_state_fields_test_() ->
         ])
     }.
 
+t_replicator_doc_state_fields_update_docs_true_test_() ->
+    {
+        setup,
+        fun setup_prefixed_replicator_db_with_update_docs_true/0,
+        fun teardown/1,
+        with([
+            ?TDEF(t_doc_fields_are_updated, 10),
+            ?TDEF(t_doc_fields_are_ignored, 10)
+        ])
+    }.
+
 t_scheduler_docs_total_rows({_Ctx, {RepDb, Source, Target}}) ->
     SourceUrl = couch_replicator_test_helper:cluster_db_url(Source),
     TargetUrl = couch_replicator_test_helper:cluster_db_url(Target),
@@ -179,7 +197,14 @@ t_doc_fields_are_updated({_Ctx, {RepDb, Source, Target}}) ->
     #{<<"_replication_state_time">> := StateTime} = StateDoc,
     ?assertNotEqual(<<"foo5">>, StateTime),
     ?assertNot(is_map_key(<<"_replicator_state_reason">>, StateDoc)),
-    ?assertNot(is_map_key(<<"_replication_id">>, StateDoc)).
+    case config:get_boolean("replicator", "update_docs", false) of
+        true ->
+            ?assertMatch(#{<<"_replication_id">> := <<_/binary>>}, StateDoc),
+            #{<<"_replication_id">> := RepId} = StateDoc,
+            ?assertNotEqual(<<"foo3">>, RepId);
+        false ->
+            ?assertNot(is_map_key(<<"_replication_id">>, StateDoc))
+    end.
 
 t_doc_fields_are_ignored({_Ctx, {RepDb, Source, Target}}) ->
     SourceUrl = couch_replicator_test_helper:cluster_db_url(Source),