diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /spec/lib/gitlab/sidekiq_middleware | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/lib/gitlab/sidekiq_middleware')
-rw-r--r-- | spec/lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job_spec.rb | 19 | ||||
-rw-r--r-- | spec/lib/gitlab/sidekiq_middleware/extra_done_log_metadata_spec.rb | 35 |
2 files changed, 47 insertions, 7 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 6e8a8c03aad..929df0a7ffb 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 @@ -113,22 +113,27 @@ describe Gitlab::SidekiqMiddleware::DuplicateJobs::DuplicateJob, :clean_gitlab_r end describe 'droppable?' do - where(:idempotent, :duplicate) do - # [true, false].repeated_permutation(2) - [[true, true], - [true, false], - [false, true], - [false, false]] + where(:idempotent, :duplicate, :prevent_deduplication) do + # [true, false].repeated_permutation(3) + [[true, true, true], + [true, true, false], + [true, false, true], + [true, false, false], + [false, true, true], + [false, true, false], + [false, false, true], + [false, false, false]] end with_them do before do allow(AuthorizedProjectsWorker).to receive(:idempotent?).and_return(idempotent) allow(duplicate_job).to receive(:duplicate?).and_return(duplicate) + stub_feature_flags("disable_#{queue}_deduplication" => prevent_deduplication) end it 'is droppable when all conditions are met' do - if idempotent && duplicate + if idempotent && duplicate && !prevent_deduplication expect(duplicate_job).to be_droppable else expect(duplicate_job).not_to be_droppable diff --git a/spec/lib/gitlab/sidekiq_middleware/extra_done_log_metadata_spec.rb b/spec/lib/gitlab/sidekiq_middleware/extra_done_log_metadata_spec.rb new file mode 100644 index 00000000000..98847885e62 --- /dev/null +++ b/spec/lib/gitlab/sidekiq_middleware/extra_done_log_metadata_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::SidekiqMiddleware::ExtraDoneLogMetadata do + # Cannot use Class.new for this as ApplicationWorker will need the class to + # have a name during `included do`. + let(:worker) { AdminEmailWorker.new } + + let(:worker_without_application_worker) do + Class.new do + end.new + end + + subject { described_class.new } + + let(:job) { { 'jid' => 123 } } + let(:queue) { 'test_queue' } + + describe '#call' do + it 'merges Application#logging_extras in to job' do + worker.log_extra_metadata_on_done(:key1, 15) + worker.log_extra_metadata_on_done(:key2, 16) + expect { |b| subject.call(worker, job, queue, &b) }.to yield_control + + expect(job).to eq({ 'jid' => 123, 'extra.admin_email_worker.key1' => 15, 'extra.admin_email_worker.key2' => 16 }) + end + + it 'does not raise when the worker does not respond to #done_log_extra_metadata' do + expect { |b| subject.call(worker_without_application_worker, job, queue, &b) }.to yield_control + + expect(job).to eq({ 'jid' => 123 }) + end + end +end |