Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2019-04-15 19:31:45 +0300
committerLin Jen-Shin <godfat@godfat.org>2019-04-15 19:31:45 +0300
commite5301b658336f387d82ff039ff9214e347c900a8 (patch)
treea4f26b00a7d63004441501757fb400e6fa90f37b /spec/services
parent57cdf56aa7df41b013d9c47c6b12bf5a9e20e4f4 (diff)
parent16259796539f19f7b04ad078a28aa38c5b50912f (diff)
Merge branch 'sh-fix-pipeline-delete-caching' into 'master'
Properly expire all pipeline caches when pipeline is deleted Closes #60469 See merge request gitlab-org/gitlab-ce!27334
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/ci/expire_pipeline_cache_service_spec.rb61
1 files changed, 61 insertions, 0 deletions
diff --git a/spec/services/ci/expire_pipeline_cache_service_spec.rb b/spec/services/ci/expire_pipeline_cache_service_spec.rb
new file mode 100644
index 00000000000..ff2d286465a
--- /dev/null
+++ b/spec/services/ci/expire_pipeline_cache_service_spec.rb
@@ -0,0 +1,61 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Ci::ExpirePipelineCacheService do
+ set(:user) { create(:user) }
+ set(:project) { create(:project) }
+ set(:pipeline) { create(:ci_pipeline, project: project) }
+ subject { described_class.new }
+
+ describe '#execute' do
+ it 'invalidates Etag caching for project pipelines path' do
+ pipelines_path = "/#{project.full_path}/pipelines.json"
+ new_mr_pipelines_path = "/#{project.full_path}/merge_requests/new.json"
+ pipeline_path = "/#{project.full_path}/pipelines/#{pipeline.id}.json"
+
+ 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
+ pipeline = create(:ci_empty_pipeline, status: 'created', project: project, ref: 'master')
+ 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.execute(pipeline)
+ end
+
+ it 'updates the cached status for a project' do
+ expect(Gitlab::Cache::Ci::ProjectPipelineStatus).to receive(:update_for_pipeline)
+ .with(pipeline)
+
+ 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