diff options
Diffstat (limited to 'spec/workers/concerns/cronjob_queue_spec.rb')
-rw-r--r-- | spec/workers/concerns/cronjob_queue_spec.rb | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/spec/workers/concerns/cronjob_queue_spec.rb b/spec/workers/concerns/cronjob_queue_spec.rb index d1ad5c65ea3..0244535051f 100644 --- a/spec/workers/concerns/cronjob_queue_spec.rb +++ b/spec/workers/concerns/cronjob_queue_spec.rb @@ -11,11 +11,33 @@ RSpec.describe CronjobQueue do include ApplicationWorker include CronjobQueue # rubocop:disable Scalability/CronWorkerContext + + def perform + AnotherWorker.perform_async('identifier') + end + end + end + + let(:another_worker) do + Class.new do + def self.name + 'AnotherWorker' + end + + include ApplicationWorker + + # To keep track of the context that was active for certain arguments + cattr_accessor(:contexts) { {} } + + def perform(identifier, *args) + self.class.contexts.merge!(identifier => Gitlab::ApplicationContext.current) + end end end before do stub_const("DummyWorker", worker) + stub_const("AnotherWorker", another_worker) end it 'sets the queue name of a worker' do @@ -27,7 +49,7 @@ RSpec.describe CronjobQueue do end it 'automatically clears project, user and namespace from the context', :aggregate_failues do - worker_context = worker.get_worker_context.to_lazy_hash.transform_values(&:call) + worker_context = worker.get_worker_context.to_lazy_hash.transform_values { |v| v.try(:call) } expect(worker_context[:user]).to be_nil expect(worker_context[:root_namespace]).to be_nil @@ -42,6 +64,14 @@ RSpec.describe CronjobQueue do expect(job).to include('meta.caller_id' => 'Cronjob') end + it 'gets root_caller_id from the cronjob' do + Sidekiq::Testing.inline! do + worker.perform_async + end + + expect(AnotherWorker.contexts['identifier']).to include('meta.root_caller_id' => 'Cronjob') + end + it 'does not set the caller_id if there was already one in the context' do Gitlab::ApplicationContext.with_context(caller_id: 'already set') do worker.perform_async |