diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-27 18:09:21 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-27 18:09:21 +0000 |
commit | e0fa0638a422c3e20d4423c9bb69d79afc9c7d3d (patch) | |
tree | 9abb3c0706576bbda895fe9539a55556930606e2 /spec/lib/gitlab/sidekiq_middleware/duplicate_jobs/strategies | |
parent | f8d15ca65390475e356b06dedc51e10ccd179f86 (diff) | |
download | gitlab-ce-e0fa0638a422c3e20d4423c9bb69d79afc9c7d3d.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/sidekiq_middleware/duplicate_jobs/strategies')
-rw-r--r-- | spec/lib/gitlab/sidekiq_middleware/duplicate_jobs/strategies/until_executing_spec.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/spec/lib/gitlab/sidekiq_middleware/duplicate_jobs/strategies/until_executing_spec.rb b/spec/lib/gitlab/sidekiq_middleware/duplicate_jobs/strategies/until_executing_spec.rb new file mode 100644 index 00000000000..f40e829f9a5 --- /dev/null +++ b/spec/lib/gitlab/sidekiq_middleware/duplicate_jobs/strategies/until_executing_spec.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' + +describe Gitlab::SidekiqMiddleware::DuplicateJobs::Strategies::UntilExecuting do + let(:fake_duplicate_job) do + instance_double(Gitlab::SidekiqMiddleware::DuplicateJobs::DuplicateJob) + end + + subject(:strategy) { described_class.new(fake_duplicate_job) } + + describe '#schedule' do + it 'checks for duplicates before yielding' do + expect(fake_duplicate_job).to receive(:check!).ordered.and_return('a jid') + expect(fake_duplicate_job).to receive(:duplicate?).ordered.and_return(false) + expect { |b| strategy.schedule({}, &b) }.to yield_control + end + + it 'adds the jid of the existing job to the job hash' do + allow(fake_duplicate_job).to receive(:check!).and_return('the jid') + job_hash = {} + + expect(fake_duplicate_job).to receive(:duplicate?).and_return(true) + expect(fake_duplicate_job).to receive(:existing_jid).and_return('the jid') + + strategy.schedule(job_hash) {} + + expect(job_hash).to include('duplicate-of' => 'the jid') + end + end + + describe '#perform' do + it 'deletes the lock before executing' do + expect(fake_duplicate_job).to receive(:delete!).ordered + expect { |b| strategy.perform({}, &b) }.to yield_control + end + end +end |