diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /spec/lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job_spec.rb | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job_spec.rb')
-rw-r--r-- | spec/lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job_spec.rb | 65 |
1 files changed, 40 insertions, 25 deletions
diff --git a/spec/lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job_spec.rb b/spec/lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job_spec.rb index 8ef61d4eae9..0285467ecab 100644 --- a/spec/lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job_spec.rb +++ b/spec/lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job_spec.rb @@ -131,31 +131,6 @@ RSpec.describe Gitlab::SidekiqMiddleware::DuplicateJobs::DuplicateJob, :clean_gi end end - describe '#droppable?' do - where(:idempotent, :prevent_deduplication) do - # [true, false].repeated_permutation(2) - [[true, true], - [true, false], - [false, true], - [false, false]] - end - - with_them do - before do - allow(AuthorizedProjectsWorker).to receive(:idempotent?).and_return(idempotent) - stub_feature_flags("disable_#{queue}_deduplication" => prevent_deduplication) - end - - it 'is droppable when all conditions are met' do - if idempotent && !prevent_deduplication - expect(duplicate_job).to be_droppable - else - expect(duplicate_job).not_to be_droppable - end - end - end - end - describe '#scheduled_at' do let(:scheduled_at) { 42 } let(:job) do @@ -181,6 +156,46 @@ RSpec.describe Gitlab::SidekiqMiddleware::DuplicateJobs::DuplicateJob, :clean_gi end end + describe '#idempotent?' do + context 'when worker class does not exist' do + let(:job) { { 'class' => '' } } + + it 'returns false' do + expect(duplicate_job).not_to be_idempotent + end + end + + context 'when worker class does not respond to #idempotent?' do + before do + stub_const('AuthorizedProjectsWorker', Class.new) + end + + it 'returns false' do + expect(duplicate_job).not_to be_idempotent + end + end + + context 'when worker class is not idempotent' do + before do + allow(AuthorizedProjectsWorker).to receive(:idempotent?).and_return(false) + end + + it 'returns false' do + expect(duplicate_job).not_to be_idempotent + end + end + + context 'when worker class is idempotent' do + before do + allow(AuthorizedProjectsWorker).to receive(:idempotent?).and_return(true) + end + + it 'returns true' do + expect(duplicate_job).to be_idempotent + end + end + end + def set_idempotency_key(key, value = '1') Sidekiq.redis { |r| r.set(key, value) } end |