2019-03-30 07:15:48 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-22 18:22:50 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ExpireJobCacheWorker do
|
2020-02-25 03:08:49 +00:00
|
|
|
let_it_be(:pipeline) { create(:ci_empty_pipeline) }
|
2017-05-22 18:22:50 +00:00
|
|
|
let(:project) { pipeline.project }
|
2019-12-17 18:07:48 +00:00
|
|
|
|
2017-05-22 18:22:50 +00:00
|
|
|
describe '#perform' do
|
|
|
|
context 'with a job in the pipeline' do
|
|
|
|
let(:job) { create(:ci_build, pipeline: pipeline) }
|
2020-02-19 18:09:10 +00:00
|
|
|
let(:job_args) { job.id }
|
|
|
|
|
|
|
|
include_examples 'an idempotent worker' do
|
|
|
|
it 'invalidates Etag caching for the job path' do
|
|
|
|
pipeline_path = "/#{project.full_path}/pipelines/#{pipeline.id}.json"
|
|
|
|
job_path = "/#{project.full_path}/builds/#{job.id}.json"
|
|
|
|
|
|
|
|
spy_store = Gitlab::EtagCaching::Store.new
|
|
|
|
|
|
|
|
allow(Gitlab::EtagCaching::Store).to receive(:new) { spy_store }
|
2017-05-22 18:22:50 +00:00
|
|
|
|
2020-02-19 18:09:10 +00:00
|
|
|
expect(spy_store).to receive(:touch)
|
2020-03-17 12:09:52 +00:00
|
|
|
.exactly(worker_exec_times).times
|
2020-02-19 18:09:10 +00:00
|
|
|
.with(pipeline_path)
|
|
|
|
.and_call_original
|
2017-05-22 18:22:50 +00:00
|
|
|
|
2020-02-19 18:09:10 +00:00
|
|
|
expect(spy_store).to receive(:touch)
|
2020-03-17 12:09:52 +00:00
|
|
|
.exactly(worker_exec_times).times
|
2020-02-19 18:09:10 +00:00
|
|
|
.with(job_path)
|
|
|
|
.and_call_original
|
2017-05-22 18:22:50 +00:00
|
|
|
|
2020-02-19 18:09:10 +00:00
|
|
|
subject
|
|
|
|
end
|
2017-05-22 18:22:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is no job in the pipeline' do
|
|
|
|
it 'does not change the etag store' do
|
|
|
|
expect(Gitlab::EtagCaching::Store).not_to receive(:new)
|
|
|
|
|
2020-02-19 18:09:10 +00:00
|
|
|
perform_multiple(9999)
|
2017-05-22 18:22:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|