2017-04-04 15:38:16 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-04-18 19:26:56 +00:00
|
|
|
describe ExpirePipelineCacheWorker do
|
2017-04-04 15:38:16 +00:00
|
|
|
let(:user) { create(:user) }
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project) }
|
2017-04-04 15:38:16 +00:00
|
|
|
let(:pipeline) { create(:ci_pipeline, project: project) }
|
2017-04-18 19:26:56 +00:00
|
|
|
subject { described_class.new }
|
2017-04-04 15:38:16 +00:00
|
|
|
|
2017-04-18 19:26:56 +00:00
|
|
|
describe '#perform' do
|
2017-04-20 06:44:01 +00:00
|
|
|
it 'invalidates Etag caching for project pipelines path' do
|
2017-04-05 14:36:14 +00:00
|
|
|
pipelines_path = "/#{project.full_path}/pipelines.json"
|
|
|
|
new_mr_pipelines_path = "/#{project.full_path}/merge_requests/new.json"
|
2017-05-22 18:22:50 +00:00
|
|
|
pipeline_path = "/#{project.full_path}/pipelines/#{pipeline.id}.json"
|
2017-04-04 15:38:16 +00:00
|
|
|
|
2017-04-05 14:36:14 +00:00
|
|
|
expect_any_instance_of(Gitlab::EtagCaching::Store).to receive(:touch).with(pipelines_path)
|
|
|
|
expect_any_instance_of(Gitlab::EtagCaching::Store).to receive(:touch).with(new_mr_pipelines_path)
|
2017-05-22 18:22:50 +00:00
|
|
|
expect_any_instance_of(Gitlab::EtagCaching::Store).to receive(:touch).with(pipeline_path)
|
2017-04-04 15:38:16 +00:00
|
|
|
|
2017-04-18 19:26:56 +00:00
|
|
|
subject.perform(pipeline.id)
|
2017-04-04 15:38:16 +00:00
|
|
|
end
|
2017-04-07 08:56:35 +00:00
|
|
|
|
2017-04-20 06:44:01 +00:00
|
|
|
it 'invalidates Etag caching for merge request pipelines if pipeline runs on any commit of that source branch' do
|
2017-04-24 08:18:37 +00:00
|
|
|
pipeline = create(:ci_empty_pipeline, status: 'created', project: project, ref: 'master')
|
2017-04-20 06:44:01 +00:00
|
|
|
merge_request = create(:merge_request, source_project: project, source_branch: pipeline.ref)
|
|
|
|
merge_request_pipelines_path = "/#{project.full_path}/merge_requests/#{merge_request.iid}/pipelines.json"
|
|
|
|
|
|
|
|
allow_any_instance_of(Gitlab::EtagCaching::Store).to receive(:touch)
|
|
|
|
expect_any_instance_of(Gitlab::EtagCaching::Store).to receive(:touch).with(merge_request_pipelines_path)
|
|
|
|
|
|
|
|
subject.perform(pipeline.id)
|
|
|
|
end
|
|
|
|
|
2017-04-21 15:39:19 +00:00
|
|
|
it "doesn't do anything if the pipeline not exist" do
|
|
|
|
expect_any_instance_of(Gitlab::EtagCaching::Store).not_to receive(:touch)
|
|
|
|
|
|
|
|
subject.perform(617748)
|
|
|
|
end
|
|
|
|
|
2017-04-07 08:56:35 +00:00
|
|
|
it 'updates the cached status for a project' do
|
2017-06-21 13:48:12 +00:00
|
|
|
expect(Gitlab::Cache::Ci::ProjectPipelineStatus).to receive(:update_for_pipeline)
|
|
|
|
.with(pipeline)
|
2017-04-07 08:56:35 +00:00
|
|
|
|
2017-04-18 19:26:56 +00:00
|
|
|
subject.perform(pipeline.id)
|
2017-04-07 08:56:35 +00:00
|
|
|
end
|
2017-04-04 15:38:16 +00:00
|
|
|
end
|
|
|
|
end
|