2019-04-12 19:29:47 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 06:09:01 +00:00
|
|
|
RSpec.describe Ci::ExpirePipelineCacheService do
|
2020-01-10 09:07:49 +00:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
|
2019-04-12 19:29:47 +00:00
|
|
|
subject { described_class.new }
|
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
it 'invalidates Etag caching for project pipelines path' do
|
2020-06-02 06:08:01 +00:00
|
|
|
pipelines_path = "/#{project.full_path}/-/pipelines.json"
|
2020-01-21 00:08:46 +00:00
|
|
|
new_mr_pipelines_path = "/#{project.full_path}/-/merge_requests/new.json"
|
2020-06-02 06:08:01 +00:00
|
|
|
pipeline_path = "/#{project.full_path}/-/pipelines/#{pipeline.id}.json"
|
2019-04-12 19:29:47 +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)
|
|
|
|
expect_any_instance_of(Gitlab::EtagCaching::Store).to receive(:touch).with(pipeline_path)
|
|
|
|
|
|
|
|
subject.execute(pipeline)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'invalidates Etag caching for merge request pipelines if pipeline runs on any commit of that source branch' do
|
2020-04-08 09:09:43 +00:00
|
|
|
merge_request = create(:merge_request, :with_detached_merge_request_pipeline)
|
|
|
|
project = merge_request.target_project
|
|
|
|
|
2020-01-21 00:08:46 +00:00
|
|
|
merge_request_pipelines_path = "/#{project.full_path}/-/merge_requests/#{merge_request.iid}/pipelines.json"
|
2019-04-12 19:29:47 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2020-04-08 09:09:43 +00:00
|
|
|
subject.execute(merge_request.all_pipelines.last)
|
2019-04-12 19:29:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates the cached status for a project' do
|
2020-04-08 09:09:43 +00:00
|
|
|
expect(Gitlab::Cache::Ci::ProjectPipelineStatus).to receive(:update_for_pipeline).with(pipeline)
|
2019-04-12 19:29:47 +00:00
|
|
|
|
|
|
|
subject.execute(pipeline)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'destroyed pipeline' do
|
|
|
|
let(:project_with_repo) { create(:project, :repository) }
|
|
|
|
let!(:pipeline_with_commit) { create(:ci_pipeline, :success, project: project_with_repo, sha: project_with_repo.commit.id) }
|
|
|
|
|
|
|
|
it 'clears the cache', :use_clean_rails_memory_store_caching do
|
|
|
|
create(:commit_status, :success, pipeline: pipeline_with_commit, ref: pipeline_with_commit.ref)
|
|
|
|
|
|
|
|
# Sanity check
|
|
|
|
expect(project_with_repo.pipeline_status.has_status?).to be_truthy
|
|
|
|
|
|
|
|
subject.execute(pipeline_with_commit, delete: true)
|
|
|
|
|
|
|
|
pipeline_with_commit.destroy!
|
|
|
|
|
|
|
|
# Need to use find to avoid memoization
|
|
|
|
expect(Project.find(project_with_repo.id).pipeline_status.has_status?).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|