Skip to content

Commit

Permalink
Fix replication job start_link.
Browse files Browse the repository at this point in the history
We don't want to register replication jobs with the module name as that
prevents us from running more than one job at a time.

This was introduced when we removed the dependence on global registrations and
switched to using pg instead.

Even more embarrassing is we didn't have tests to check multiple replication
jobs running at the same time.
  • Loading branch information
nickva authored and janl committed Jan 6, 2023
1 parent 0d29e16 commit a840dc9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ start_link(#rep{id = Id = {BaseId, Ext}, source = Src, target = Tgt} = Rep) ->
Target = couch_replicator_api_wrap:db_uri(Tgt),
case couch_replicator_pg:should_start(Id, node()) of
yes ->
case gen_server:start_link({local, ?MODULE}, ?MODULE, Rep, []) of
case gen_server:start_link(?MODULE, Rep, []) of
{ok, Pid} ->
couch_replicator_pg:join(Id, Pid),
{ok, Pid};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ error_reporting_test_() ->
?TDEF_FE(t_fail_changes_manager),
?TDEF_FE(t_fail_changes_reader_proc),
?TDEF_FE(t_dont_start_duplicate_job),
?TDEF_FE(t_can_start_multiple_jobs),
?TDEF_FE(t_stop_duplicate_job)
]
}.
Expand Down Expand Up @@ -160,6 +161,30 @@ t_dont_start_duplicate_job({_Ctx, {Source, Target}}) ->
ExpectErr = {error, {already_started, Pid}},
?assertEqual(ExpectErr, couch_replicator_scheduler_job:start_link(Rep)).

t_can_start_multiple_jobs({_Ctx, {Source, Target1}}) ->
Target2 = couch_replicator_test_helper:setup_db(),
populate_db(Source, 1, 5),

{ok, RepId1} = replicate(Source, Target1),
{ok, RepId2} = replicate(Source, Target2),
RepPid1 = couch_replicator_test_helper:get_pid(RepId1),
RepPid2 = couch_replicator_test_helper:get_pid(RepId2),
?assert(is_pid(RepPid1)),
?assert(is_pid(RepPid2)),

?assert(is_process_alive(RepPid1)),
?assert(is_process_alive(RepPid2)),

wait_target_in_sync(Source, Target1),
wait_target_in_sync(Source, Target2),

?assert(is_process_alive(RepPid1)),
?assert(is_process_alive(RepPid2)),

exit(RepPid1, kill),
exit(RepPid2, kill),
couch_replicator_test_helper:teardown_db(Target2).

t_stop_duplicate_job({_Ctx, {Source, Target}}) ->
{ok, RepId} = replicate(Source, Target),
wait_target_in_sync(Source, Target),
Expand Down

0 comments on commit a840dc9

Please sign in to comment.