Skip to content

Commit

Permalink
Test the update_docs=true case in replicator scheduler docs test
Browse files Browse the repository at this point in the history
For completeness, make sure to test replicator doc updates with
`update_docs=true` setting as well.

Issue: #4423
  • Loading branch information
nickva committed Feb 14, 2023
1 parent 0867d1b commit d3b0bcb
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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_() ->
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit d3b0bcb

Please sign in to comment.