Commit 38d9b4d7 authored by Shinya Maeda's avatar Shinya Maeda

Use script_failure. Add runner_system_failure. Improve spec.

parent 5d50cbfa
......@@ -40,9 +40,10 @@ class CommitStatus < ActiveRecord::Base
enum failure_reason: {
unknown_failure: nil,
job_failure: 1,
script_failure: 1,
api_failure: 2,
stuck_or_timeout_failure: 3
stuck_or_timeout_failure: 3,
runner_system_failure: 4
}
state_machine :status do
......
......@@ -53,7 +53,7 @@ module Projects
log_error("Projects::UpdatePagesService: #{message}")
@status.allow_failure = !latest?
@status.description = message
@status.drop(:job_failure)
@status.drop(:script_failure)
super
end
......
......@@ -129,8 +129,7 @@ module API
when 'success'
job.success
when 'failed'
failure_reason = params[:failure_reason] ? params[:failure_reason].to_sym : :unknown_failure
job.drop(failure_reason)
job.drop(params[:failure_reason] || :unknown_failure)
end
end
......
......@@ -458,10 +458,10 @@ describe CommitStatus do
it { is_expected.to be_unknown_failure }
end
context 'when failure_reason is job_failure' do
let(:reason) { :job_failure }
context 'when failure_reason is script_failure' do
let(:reason) { :script_failure }
it { is_expected.to be_job_failure }
it { is_expected.to be_script_failure }
end
end
end
......@@ -626,24 +626,34 @@ describe API::Runner do
it 'mark job as succeeded' do
update_job(state: 'success')
expect(job.reload.status).to eq 'success'
expect(job).to be_unknown_failure
job.reload
expect(job).to be_success
end
it 'mark job as failed' do
update_job(state: 'failed')
expect(job.reload.status).to eq 'failed'
expect(job).to be_job_failure
job.reload
expect(job).to be_failed
expect(job).to be_unknown_failure
end
context 'when failure_reason is given' do
it 'mark job as failed' do
update_job(state: 'failed', failure_reason: 'stuck_or_timeout_failure')
context 'when failure_reason is script_failure' do
before do
update_job(state: 'failed', failure_reason: 'script_failure')
job.reload
end
it { expect(job).to be_script_failure }
end
expect(job.reload.status).to eq 'failed'
expect(job).to be_stuck_or_timeout_failure
context 'when failure_reason is runner_system_failure' do
before do
update_job(state: 'failed', failure_reason: 'runner_system_failure')
job.reload
end
it { expect(job).to be_runner_system_failure }
end
end
......
......@@ -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_job_failure
expect(deploy_status).to be_script_failure
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