Commit 47abf00b authored by Bob Van Landuyt's avatar Bob Van Landuyt

Update project build status cache when transitioning

parent 9082d1e0
...@@ -31,7 +31,6 @@ module Ci ...@@ -31,7 +31,6 @@ module Ci
validate :valid_commit_sha, unless: :importing? validate :valid_commit_sha, unless: :importing?
after_create :keep_around_commits, unless: :importing? after_create :keep_around_commits, unless: :importing?
after_create :refresh_build_status_cache
state_machine :status, initial: :created do state_machine :status, initial: :created do
event :enqueue do event :enqueue do
...@@ -99,6 +98,7 @@ module Ci ...@@ -99,6 +98,7 @@ module Ci
PipelineHooksWorker.perform_async(id) PipelineHooksWorker.perform_async(id)
Ci::ExpirePipelineCacheService.new(project, nil) Ci::ExpirePipelineCacheService.new(project, nil)
.execute(pipeline) .execute(pipeline)
refresh_project_build_status_cache
end end
end end
...@@ -351,7 +351,6 @@ module Ci ...@@ -351,7 +351,6 @@ module Ci
when 'manual' then block when 'manual' then block
end end
end end
refresh_build_status_cache
end end
def predefined_variables def predefined_variables
...@@ -393,7 +392,7 @@ module Ci ...@@ -393,7 +392,7 @@ module Ci
.fabricate! .fabricate!
end 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 Gitlab::Cache::Ci::ProjectBuildStatus.new(project, sha: sha, status: status).store_in_cache_if_needed
end end
......
...@@ -251,7 +251,8 @@ module SharedProject ...@@ -251,7 +251,8 @@ module SharedProject
step 'project "Shop" has CI build' do step 'project "Shop" has CI build' do
project = Project.find_by(name: "Shop") 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 end
step 'I should see last commit with CI status' do step 'I should see last commit with CI status' do
......
...@@ -7,7 +7,6 @@ RSpec.describe 'Dashboard Projects', feature: true do ...@@ -7,7 +7,6 @@ RSpec.describe 'Dashboard Projects', feature: true do
before do before do
project.team << [user, :developer] project.team << [user, :developer]
login_as user login_as user
visit dashboard_projects_path
end end
it 'shows the project the user in a member of in the list' do 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 ...@@ -15,15 +14,19 @@ RSpec.describe 'Dashboard Projects', feature: true do
expect(page).to have_content('awesome stuff') expect(page).to have_content('awesome stuff')
end end
describe "with a pipeline" do describe "with a pipeline", redis: true do
let(:pipeline) { create(:ci_pipeline, :success, project: project, sha: project.commit.sha) } let!(:pipeline) { create(:ci_pipeline, project: project, sha: project.commit.sha) }
before do 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 end
it 'shows that the last pipeline passed' do it 'shows that the last pipeline passed' do
visit dashboard_projects_path visit dashboard_projects_path
expect(page).to have_xpath("//a[@href='#{pipelines_namespace_project_commit_path(project.namespace, project, project.commit)}']") expect(page).to have_xpath("//a[@href='#{pipelines_namespace_project_commit_path(project.namespace, project, project.commit)}']")
end end
end end
......
...@@ -63,7 +63,7 @@ describe ProjectsHelper do ...@@ -63,7 +63,7 @@ describe ProjectsHelper do
end end
end end
describe "#project_list_cache_key" do describe "#project_list_cache_key", redis: true do
let(:project) { create(:project) } let(:project) { create(:project) }
it "includes the namespace" do it "includes the namespace" do
......
...@@ -1079,17 +1079,18 @@ describe Ci::Pipeline, models: true do ...@@ -1079,17 +1079,18 @@ describe Ci::Pipeline, models: true do
end end
end end
describe '#update_status' do describe 'update project cache when transitioning' do
let(:pipeline) { create(:ci_pipeline, sha: '123456') } let(:pipeline) { create(:ci_pipeline, sha: '123456') }
it 'updates the cached status' do it 'updates the cached status' do
fake_status = double fake_status = double
expect(Gitlab::Cache::Ci::ProjectBuildStatus).to receive(:new). 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) and_return(fake_status)
expect(fake_status).to receive(:store_in_cache_if_needed) expect(fake_status).to receive(:store_in_cache_if_needed)
pipeline.update_status pipeline.block
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment