diff options
author | Bob Van Landuyt <bob@gitlab.com> | 2017-03-30 09:15:42 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@gitlab.com> | 2017-04-07 17:24:11 +0200 |
commit | 47abf00b24efb0f6263ea37eddf2d6587950c5ee (patch) | |
tree | 9159be8bffb2208834b23a0633a097fdb92f103c | |
parent | 9082d1e046a8da394ea0b271f9f3fea909bb102c (diff) | |
download | gitlab-ce-47abf00b24efb0f6263ea37eddf2d6587950c5ee.tar.gz |
Update project build status cache when transitioning
-rw-r--r-- | app/models/ci/pipeline.rb | 5 | ||||
-rw-r--r-- | features/steps/shared/project.rb | 3 | ||||
-rw-r--r-- | spec/features/dashboard/projects_spec.rb | 11 | ||||
-rw-r--r-- | spec/helpers/projects_helper_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 7 |
5 files changed, 16 insertions, 12 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 8ee1a0580e1..b1cabbcd53e 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -31,7 +31,6 @@ module Ci validate :valid_commit_sha, unless: :importing? after_create :keep_around_commits, unless: :importing? - after_create :refresh_build_status_cache state_machine :status, initial: :created do event :enqueue do @@ -99,6 +98,7 @@ module Ci PipelineHooksWorker.perform_async(id) Ci::ExpirePipelineCacheService.new(project, nil) .execute(pipeline) + refresh_project_build_status_cache end end @@ -351,7 +351,6 @@ module Ci when 'manual' then block end end - refresh_build_status_cache end def predefined_variables @@ -393,7 +392,7 @@ module Ci .fabricate! end - def refresh_build_status_cache + def refresh_project_build_status_cache Gitlab::Cache::Ci::ProjectBuildStatus.new(project, sha: sha, status: status).store_in_cache_if_needed end diff --git a/features/steps/shared/project.rb b/features/steps/shared/project.rb index 4ee879fe922..73206c3f30d 100644 --- a/features/steps/shared/project.rb +++ b/features/steps/shared/project.rb @@ -251,7 +251,8 @@ module SharedProject step 'project "Shop" has CI build' do project = Project.find_by(name: "Shop") - create :ci_pipeline, project: project, sha: project.commit.sha, ref: 'master', status: 'skipped' + pipeline = create :ci_pipeline, project: project, sha: project.commit.sha, ref: 'master' + pipeline.skip end step 'I should see last commit with CI status' do diff --git a/spec/features/dashboard/projects_spec.rb b/spec/features/dashboard/projects_spec.rb index c4e58d14f75..f1789fc9d43 100644 --- a/spec/features/dashboard/projects_spec.rb +++ b/spec/features/dashboard/projects_spec.rb @@ -7,7 +7,6 @@ RSpec.describe 'Dashboard Projects', feature: true do before do project.team << [user, :developer] login_as user - visit dashboard_projects_path end it 'shows the project the user in a member of in the list' do @@ -15,15 +14,19 @@ RSpec.describe 'Dashboard Projects', feature: true do expect(page).to have_content('awesome stuff') end - describe "with a pipeline" do - let(:pipeline) { create(:ci_pipeline, :success, project: project, sha: project.commit.sha) } + describe "with a pipeline", redis: true do + let!(:pipeline) { create(:ci_pipeline, project: project, sha: project.commit.sha) } before do - pipeline + # Since the cache isn't updated when a new pipeline is created + # we need the pipeline to advance in the pipeline since the cache was created + # by visiting the login page. + pipeline.succeed end it 'shows that the last pipeline passed' do visit dashboard_projects_path + expect(page).to have_xpath("//a[@href='#{pipelines_namespace_project_commit_path(project.namespace, project, project.commit)}']") end end diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index 44312ada438..40efab6e4f7 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -63,7 +63,7 @@ describe ProjectsHelper do end end - describe "#project_list_cache_key" do + describe "#project_list_cache_key", redis: true do let(:project) { create(:project) } it "includes the namespace" do diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 3f893fd3166..5caba6ae703 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -1079,17 +1079,18 @@ describe Ci::Pipeline, models: true do end end - describe '#update_status' do + describe 'update project cache when transitioning' do let(:pipeline) { create(:ci_pipeline, sha: '123456') } it 'updates the cached status' do fake_status = double expect(Gitlab::Cache::Ci::ProjectBuildStatus).to receive(:new). - with(pipeline.project, sha: '123456', status: 'skipped'). + with(pipeline.project, sha: '123456', status: 'manual'). and_return(fake_status) + expect(fake_status).to receive(:store_in_cache_if_needed) - pipeline.update_status + pipeline.block end end |