Fix enum lists

This commit is contained in:
Shinya Maeda 2017-08-31 22:03:41 +09:00
parent b1af1f268b
commit 1d7c039072
12 changed files with 34 additions and 40 deletions

View file

@ -103,7 +103,7 @@ module Ci
end
end
before_transition any => [:failed] do |build, transition|
before_transition any => [:failed] do |build|
next if build.retries_max.zero?
if build.retries_count < build.retries_max

View file

@ -39,16 +39,10 @@ class CommitStatus < ActiveRecord::Base
scope :after_stage, -> (index) { where('stage_idx > ?', index) }
enum failure_reason: {
no_error: nil,
failed_by_script: 1, # TODO: Not used. Should we expand pipeline as well?
failed_by_missing_dependency: 2, # This will be done in the next MR.
failed_by_system: 3, # TODO: Not used. What's this state?
failed_by_job_state: 4,
failed_by_out_of_quota: 5, # TODO: Only EE. How can we detect?
failed_by_stuck_and_timeout: 6,
failed_by_no_runner: 7, # TODO: Not used. How can we detect?
failed_by_api: 8,
failed_by_page: 9
unknown_failure: nil,
job_failure: 1,
api_failure: 2,
stuck_or_timeout_failure: 3,
}
state_machine :status do

View file

@ -53,7 +53,7 @@ module Projects
log_error("Projects::UpdatePagesService: #{message}")
@status.allow_failure = !latest?
@status.description = message
@status.drop(:failed_by_page)
@status.drop(:job_failure)
super
end

View file

@ -53,7 +53,7 @@ class StuckCiJobsWorker
def drop_build(type, build, status, timeout)
Rails.logger.info "#{self.class}: Dropping #{type} build #{build.id} for runner #{build.runner_id} (status: #{status}, timeout: #{timeout})"
Gitlab::OptimisticLocking.retry_lock(build, 3) do |b|
b.drop(:failed_by_stuck_and_timeout)
b.drop(:stuck_or_timeout_failure)
end
end
end

View file

@ -103,7 +103,7 @@ module API
when 'success'
status.success!
when 'failed'
status.drop!(:failed_by_api)
status.drop!(:api_failure)
when 'canceled'
status.cancel!
else

View file

@ -127,7 +127,7 @@ module API
when 'success'
job.success
when 'failed'
job.drop(:failed_job_state)
job.drop(:job_failure)
end
end

View file

@ -1710,24 +1710,4 @@ describe Ci::Build do
end
end
end
describe 'set failure_reason when drop' do
let(:build) { create(:ci_build, :created) }
before do
build.drop!(reason)
end
context 'when failure_reason is nil' do
let(:reason) { }
it { expect(build).to be_no_error }
end
context 'when failure_reason is script_error' do
let(:reason) { :script_error }
it { expect(build).to be_failed_by_missing_dependency }
end
end
end

View file

@ -443,4 +443,24 @@ describe CommitStatus do
end
end
end
describe 'set failure_reason when drop' do
let(:build) { create(:ci_build, :created) }
before do
build.drop!(reason)
end
context 'when failure_reason is nil' do
let(:reason) { }
it { expect(build).to be_unknown_failure }
end
context 'when failure_reason is job_failure' do
let(:reason) { :job_failure }
it { expect(build).to be_job_failure }
end
end
end

View file

@ -143,7 +143,7 @@ describe API::CommitStatuses do
expect(json_response['target_url']).to be_nil
expect(json_response['description']).to be_nil
if status == 'failed'
expect(CommitStatus.find(json_response['id'])).to be_failed_by_api
expect(CommitStatus.find(json_response['id'])).to be_api_failure
end
end
end

View file

@ -627,14 +627,14 @@ describe API::Runner do
update_job(state: 'success')
expect(job.reload.status).to eq 'success'
expect(job).to be_no_error
expect(job).to be_unknown_failure
end
it 'mark job as failed' do
update_job(state: 'failed')
expect(job.reload.status).to eq 'failed'
expect(job).to be_failed_by_job_state
expect(job).to be_job_failure
end
end

View file

@ -116,7 +116,7 @@ describe Projects::UpdatePagesService do
expect(deploy_status.description)
.to match(/artifacts for pages are too large/)
expect(deploy_status).to be_failed_by_page
expect(deploy_status).to be_job_failure
end
end

View file

@ -20,7 +20,7 @@ describe StuckCiJobsWorker do
it 'changes status' do
worker.perform
is_expected.to eq('failed')
expect(job).to be_failed_by_stuck_and_timeout
expect(job).to be_stuck_or_timeout_failure
end
end