Commit 4ccf39cd authored by Kamil Trzcinski's avatar Kamil Trzcinski

Fix test failures, that did occur because of missing previously used `reload_status!` call

parent 6a6a69f4
...@@ -42,24 +42,25 @@ module Ci ...@@ -42,24 +42,25 @@ module Ci
end end
def retry(build, user = nil) def retry(build, user = nil)
new_build = Ci::Build.new(status: 'pending') new_build = Ci::Build.create(
new_build.ref = build.ref ref: build.ref,
new_build.tag = build.tag tag: build.tag,
new_build.options = build.options options: build.options,
new_build.commands = build.commands commands: build.commands,
new_build.tag_list = build.tag_list tag_list: build.tag_list,
new_build.project = build.project project: build.project,
new_build.pipeline = build.pipeline pipeline: build.pipeline,
new_build.name = build.name name: build.name,
new_build.allow_failure = build.allow_failure allow_failure: build.allow_failure,
new_build.stage = build.stage stage: build.stage,
new_build.stage_idx = build.stage_idx stage_idx: build.stage_idx,
new_build.trigger_request = build.trigger_request trigger_request: build.trigger_request,
new_build.yaml_variables = build.yaml_variables yaml_variables: build.yaml_variables,
new_build.when = build.when when: build.when,
new_build.user = user user: user,
new_build.environment = build.environment environment: build.environment,
new_build.save status_event: 'queue'
)
MergeRequests::AddTodoWhenBuildFailsService.new(build.project, nil).close(new_build) MergeRequests::AddTodoWhenBuildFailsService.new(build.project, nil).close(new_build)
new_build new_build
end end
......
...@@ -62,14 +62,6 @@ class CommitStatus < ActiveRecord::Base ...@@ -62,14 +62,6 @@ class CommitStatus < ActiveRecord::Base
commit_status.update_attributes finished_at: Time.now commit_status.update_attributes finished_at: Time.now
end end
after_transition [:created, :pending, :running] => :success do |commit_status|
MergeRequests::MergeWhenBuildSucceedsService.new(commit_status.pipeline.project, nil).trigger(commit_status)
end
after_transition any => :failed do |commit_status|
MergeRequests::AddTodoWhenBuildFailsService.new(commit_status.pipeline.project, nil).execute(commit_status)
end
# We use around_transition to process pipeline on next stages as soon as possible, before the `after_*` is executed # We use around_transition to process pipeline on next stages as soon as possible, before the `after_*` is executed
around_transition any => [:success, :failed, :canceled] do |commit_status, block| around_transition any => [:success, :failed, :canceled] do |commit_status, block|
block.call block.call
...@@ -77,11 +69,17 @@ class CommitStatus < ActiveRecord::Base ...@@ -77,11 +69,17 @@ class CommitStatus < ActiveRecord::Base
commit_status.pipeline.try(:process!) commit_status.pipeline.try(:process!)
end end
# Try to update the pipeline status
after_transition do |commit_status, transition| after_transition do |commit_status, transition|
commit_status.pipeline.try(:update_status) unless transition.loopback? commit_status.pipeline.try(:update_status) unless transition.loopback?
end end
after_transition [:created, :pending, :running] => :success do |commit_status|
MergeRequests::MergeWhenBuildSucceedsService.new(commit_status.pipeline.project, nil).trigger(commit_status)
end
after_transition any => :failed do |commit_status|
MergeRequests::AddTodoWhenBuildFailsService.new(commit_status.pipeline.project, nil).execute(commit_status)
end
end end
delegate :sha, :short_sha, to: :pipeline delegate :sha, :short_sha, to: :pipeline
......
...@@ -23,7 +23,7 @@ module SharedBuilds ...@@ -23,7 +23,7 @@ module SharedBuilds
end end
step 'project has another build that is running' do step 'project has another build that is running' do
create(:ci_build, pipeline: @pipeline, name: 'second build', status: 'running') create(:ci_build, pipeline: @pipeline, name: 'second build', status_event: 'run')
end end
step 'I visit recent build details page' do step 'I visit recent build details page' do
......
...@@ -12,7 +12,7 @@ describe "Pipelines" do ...@@ -12,7 +12,7 @@ describe "Pipelines" do
end end
describe 'GET /:project/pipelines' do describe 'GET /:project/pipelines' do
let!(:pipeline) { create(:ci_pipeline, project: project, ref: 'master', status: 'running') } let!(:pipeline) { create(:ci_empty_pipeline, project: project, ref: 'master', status: 'running') }
[:all, :running, :branches].each do |scope| [:all, :running, :branches].each do |scope|
context "displaying #{scope}" do context "displaying #{scope}" do
...@@ -31,9 +31,10 @@ describe "Pipelines" do ...@@ -31,9 +31,10 @@ describe "Pipelines" do
end end
context 'cancelable pipeline' do context 'cancelable pipeline' do
let!(:running) { create(:ci_build, :running, pipeline: pipeline, stage: 'test', commands: 'test') } let!(:build) { create(:ci_build, pipeline: pipeline, stage: 'test', commands: 'test') }
before do before do
build.run
visit namespace_project_pipelines_path(project.namespace, project) visit namespace_project_pipelines_path(project.namespace, project)
end end
...@@ -49,9 +50,10 @@ describe "Pipelines" do ...@@ -49,9 +50,10 @@ describe "Pipelines" do
end end
context 'retryable pipelines' do context 'retryable pipelines' do
let!(:failed) { create(:ci_build, :failed, pipeline: pipeline, stage: 'test', commands: 'test') } let!(:build) { create(:ci_build, pipeline: pipeline, stage: 'test', commands: 'test') }
before do before do
build.drop
visit namespace_project_pipelines_path(project.namespace, project) visit namespace_project_pipelines_path(project.namespace, project)
end end
...@@ -98,9 +100,10 @@ describe "Pipelines" do ...@@ -98,9 +100,10 @@ describe "Pipelines" do
end end
context 'when failed' do context 'when failed' do
let!(:failed) { create(:generic_commit_status, status: 'failed', pipeline: pipeline, stage: 'test') } let!(:status) { create(:generic_commit_status, :pending, pipeline: pipeline, stage: 'test') }
before do before do
status.drop
visit namespace_project_pipelines_path(project.namespace, project) visit namespace_project_pipelines_path(project.namespace, project)
end end
......
...@@ -2,21 +2,23 @@ require 'spec_helper' ...@@ -2,21 +2,23 @@ require 'spec_helper'
describe Ci::Charts, lib: true do describe Ci::Charts, lib: true do
context "build_times" do context "build_times" do
let(:project) { create(:empty_project) }
let(:chart) { Ci::Charts::BuildTime.new(project) }
subject { chart.build_times }
before do before do
@pipeline = FactoryGirl.create(:ci_pipeline) create(:ci_empty_pipeline, project: project, duration: 120)
FactoryGirl.create(:ci_build, pipeline: @pipeline)
end end
it 'returns build times in minutes' do it 'returns build times in minutes' do
chart = Ci::Charts::BuildTime.new(@pipeline.project) is_expected.to contain_exactly(2)
expect(chart.build_times).to eq([2])
end end
it 'handles nil build times' do it 'handles nil build times' do
create(:ci_pipeline, duration: nil, project: @pipeline.project) create(:ci_empty_pipeline, project: project, duration: nil)
chart = Ci::Charts::BuildTime.new(@pipeline.project) is_expected.to contain_exactly(2, 0)
expect(chart.build_times).to eq([2, 0])
end end
end end
end end
...@@ -120,22 +120,18 @@ describe Ci::Pipeline, models: true do ...@@ -120,22 +120,18 @@ describe Ci::Pipeline, models: true do
end end
end end
describe '#update_counters' do describe '#duration' do
let(:pipeline) { create :ci_empty_pipeline, project: project }
context 'updates' do
let(:current) { Time.now.change(usec: 0) } let(:current) { Time.now.change(usec: 0) }
let(:build) { FactoryGirl.create :ci_build, pipeline: pipeline, started_at: current - 120, finished_at: current - 60 } let!(:build) { create :ci_build, name: 'build1', pipeline: pipeline, started_at: current - 60, finished_at: current }
let!(:build2) { create :ci_build, name: 'build2', pipeline: pipeline, started_at: current - 60, finished_at: current }
before do before do
build.skip build.skip
build2.skip
end end
[:status, :started_at, :finished_at, :duration].each do |param| it 'matches sum of builds duration' do
it "#{param}" do expect(pipeline.reload.duration).to eq(build.duration + build2.duration)
expect(pipeline.reload.send(param)).to eq(build.send(param))
end
end
end end
end end
......
...@@ -9,7 +9,7 @@ describe API::API, api: true do ...@@ -9,7 +9,7 @@ describe API::API, api: true do
let!(:developer) { create(:project_member, :developer, user: user, project: project) } let!(:developer) { create(:project_member, :developer, user: user, project: project) }
let(:reporter) { create(:project_member, :reporter, project: project) } let(:reporter) { create(:project_member, :reporter, project: project) }
let(:guest) { create(:project_member, :guest, project: project) } let(:guest) { create(:project_member, :guest, project: project) }
let!(:pipeline) { create(:ci_pipeline, project: project, sha: project.commit.id, ref: project.default_branch) } let!(:pipeline) { create(:ci_empty_pipeline, project: project, sha: project.commit.id, ref: project.default_branch) }
let!(:build) { create(:ci_build, pipeline: pipeline) } let!(:build) { create(:ci_build, pipeline: pipeline) }
describe 'GET /projects/:id/builds ' do describe 'GET /projects/:id/builds ' do
...@@ -174,7 +174,11 @@ describe API::API, api: true do ...@@ -174,7 +174,11 @@ describe API::API, api: true do
describe 'GET /projects/:id/artifacts/:ref_name/download?job=name' do describe 'GET /projects/:id/artifacts/:ref_name/download?job=name' do
let(:api_user) { reporter.user } let(:api_user) { reporter.user }
let(:build) { create(:ci_build, :success, :artifacts, pipeline: pipeline) } let(:build) { create(:ci_build, :artifacts, pipeline: pipeline) }
before do
build.success
end
def path_for_ref(ref = pipeline.ref, job = build.name) def path_for_ref(ref = pipeline.ref, job = build.name)
api("/projects/#{project.id}/builds/artifacts/#{ref}/download?job=#{job}", api_user) api("/projects/#{project.id}/builds/artifacts/#{ref}/download?job=#{job}", api_user)
......
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