diff options
author | Nick Vatamaniuc <vatamane@gmail.com> | 2023-01-06 01:41:29 -0500 |
---|---|---|
committer | Jan Lehnardt <jan@apache.org> | 2023-01-06 10:34:50 +0100 |
commit | 1a2a26a4b9c5088514f8eff8535e81b5bef14c9f (patch) | |
tree | 75919b53a2b179d8f73886322d3204248479f1cc | |
parent | 1117b85b760c1385a7f04f6cec1123853874e9ea (diff) | |
download | couchdb-1a2a26a4b9c5088514f8eff8535e81b5bef14c9f.tar.gz |
Fix replication job start_link.
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.
-rw-r--r-- | src/couch_replicator/src/couch_replicator_scheduler_job.erl | 2 | ||||
-rw-r--r-- | src/couch_replicator/test/eunit/couch_replicator_error_reporting_tests.erl | 25 |
2 files changed, 26 insertions, 1 deletions
diff --git a/src/couch_replicator/src/couch_replicator_scheduler_job.erl b/src/couch_replicator/src/couch_replicator_scheduler_job.erl index 416220efd..e16412e4a 100644 --- a/src/couch_replicator/src/couch_replicator_scheduler_job.erl +++ b/src/couch_replicator/src/couch_replicator_scheduler_job.erl @@ -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}; diff --git a/src/couch_replicator/test/eunit/couch_replicator_error_reporting_tests.erl b/src/couch_replicator/test/eunit/couch_replicator_error_reporting_tests.erl index dd6609941..d9c6a1048 100644 --- a/src/couch_replicator/test/eunit/couch_replicator_error_reporting_tests.erl +++ b/src/couch_replicator/test/eunit/couch_replicator_error_reporting_tests.erl @@ -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) ] }. @@ -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), |