diff options
author | Benjamin Neff <benjamin@coding4coffee.ch> | 2017-09-28 03:53:35 +0300 |
---|---|---|
committer | Benjamin Neff <benjamin@coding4coffee.ch> | 2017-09-29 00:11:46 +0300 |
commit | fd36517dee51d9d78796d81242f91a72f65165b2 (patch) | |
tree | 0b20593e6c6e914c0f7fe12660287c5429d1dde0 /spec/workers | |
parent | b8fb4b62515b8bdcfb1052df7d51afef0ba35966 (diff) |
Limit the number of parallel exports that are allowed to run
closes #7629
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/export_user_spec.rb | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/spec/workers/export_user_spec.rb b/spec/workers/export_user_spec.rb index 72b0c341f..e72410149 100644 --- a/spec/workers/export_user_spec.rb +++ b/spec/workers/export_user_spec.rb @@ -22,4 +22,68 @@ describe Workers::ExportUser do expect(ExportMailer).to receive(:export_failure_for).with(alice).and_call_original Workers::ExportUser.new.perform(alice.id) end + + context "concurrency" do + before do + AppConfig.environment.single_process_mode = false + AppConfig.settings.export_concurrency = 1 + end + + after :all do + AppConfig.environment.single_process_mode = true + end + + let(:pid) { "#{Socket.gethostname}:#{Process.pid}:#{SecureRandom.hex(6)}" } + + it "schedules a job for later when already another parallel export job is running" do + expect(Sidekiq::Workers).to receive(:new).and_return( + [[pid, SecureRandom.hex(4), {"payload" => {"class" => "Workers::ExportUser"}}]] + ) + + expect(Workers::ExportUser).to receive(:perform_in).with(kind_of(Integer), alice.id) + expect(alice).not_to receive(:perform_export!) + + Workers::ExportUser.new.perform(alice.id) + end + + it "runs the export when the own running job" do + expect(Sidekiq::Workers).to receive(:new).and_return( + [[pid, Thread.current.object_id.to_s(36), {"payload" => {"class" => "Workers::ExportUser"}}]] + ) + + expect(Workers::ExportUser).not_to receive(:perform_in).with(kind_of(Integer), alice.id) + expect(alice).to receive(:perform_export!) + + Workers::ExportUser.new.perform(alice.id) + end + + it "runs the export when no other job is running" do + expect(Sidekiq::Workers).to receive(:new).and_return([]) + + expect(Workers::ExportUser).not_to receive(:perform_in).with(kind_of(Integer), alice.id) + expect(alice).to receive(:perform_export!) + + Workers::ExportUser.new.perform(alice.id) + end + + it "runs the export when some other job is running" do + expect(Sidekiq::Workers).to receive(:new).and_return( + [[pid, SecureRandom.hex(4), {"payload" => {"class" => "Workers::OtherJob"}}]] + ) + + expect(Workers::ExportUser).not_to receive(:perform_in).with(kind_of(Integer), alice.id) + expect(alice).to receive(:perform_export!) + + Workers::ExportUser.new.perform(alice.id) + end + + it "runs the export when diaspora is in single process mode" do + AppConfig.environment.single_process_mode = true + expect(Sidekiq::Workers).not_to receive(:new) + expect(Workers::ExportUser).not_to receive(:perform_in).with(kind_of(Integer), alice.id) + expect(alice).to receive(:perform_export!) + + Workers::ExportUser.new.perform(alice.id) + end + end end |