2019-03-30 07:15:48 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-21 16:13:41 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 15:08:50 +00:00
|
|
|
RSpec.describe CronjobQueue do
|
2016-10-21 16:13:41 +00:00
|
|
|
let(:worker) do
|
|
|
|
Class.new do
|
2017-11-28 16:08:30 +00:00
|
|
|
def self.name
|
|
|
|
'DummyWorker'
|
|
|
|
end
|
|
|
|
|
|
|
|
include ApplicationWorker
|
2020-02-04 15:08:40 +00:00
|
|
|
include CronjobQueue # rubocop:disable Scalability/CronWorkerContext
|
2016-10-21 16:13:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-15 18:09:36 +00:00
|
|
|
before do
|
|
|
|
stub_const("DummyWorker", worker)
|
|
|
|
end
|
|
|
|
|
2016-10-21 16:13:41 +00:00
|
|
|
it 'sets the queue name of a worker' do
|
2017-11-28 16:16:50 +00:00
|
|
|
expect(worker.sidekiq_options['queue'].to_s).to eq('cronjob:dummy')
|
2016-10-21 16:13:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'disables retrying of failed jobs' do
|
|
|
|
expect(worker.sidekiq_options['retry']).to eq(false)
|
|
|
|
end
|
2020-01-24 12:09:01 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
expect(worker_context[:user]).to be_nil
|
|
|
|
expect(worker_context[:root_namespace]).to be_nil
|
|
|
|
expect(worker_context[:project]).to be_nil
|
|
|
|
end
|
2020-04-15 18:09:36 +00:00
|
|
|
|
|
|
|
it 'gets scheduled with caller_id set to Cronjob' do
|
|
|
|
worker.perform_async
|
|
|
|
|
|
|
|
job = worker.jobs.last
|
|
|
|
|
|
|
|
expect(job).to include('meta.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
|
|
|
|
end
|
|
|
|
|
|
|
|
job = worker.jobs.last
|
|
|
|
|
|
|
|
expect(job).to include('meta.caller_id' => 'already set')
|
|
|
|
end
|
2016-10-21 16:13:41 +00:00
|
|
|
end
|