Fix enum lists
This commit is contained in:
		
							parent
							
								
									b1af1f268b
								
							
						
					
					
						commit
						1d7c039072
					
				| 
						 | 
					@ -103,7 +103,7 @@ module Ci
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      before_transition any => [:failed] do |build, transition|
 | 
					      before_transition any => [:failed] do |build|
 | 
				
			||||||
        next if build.retries_max.zero?
 | 
					        next if build.retries_max.zero?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if build.retries_count < build.retries_max
 | 
					        if build.retries_count < build.retries_max
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -39,16 +39,10 @@ class CommitStatus < ActiveRecord::Base
 | 
				
			||||||
  scope :after_stage, -> (index) { where('stage_idx > ?', index) }
 | 
					  scope :after_stage, -> (index) { where('stage_idx > ?', index) }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  enum failure_reason: {
 | 
					  enum failure_reason: {
 | 
				
			||||||
    no_error: nil,
 | 
					    unknown_failure: nil,
 | 
				
			||||||
    failed_by_script: 1, # TODO: Not used. Should we expand pipeline as well?
 | 
					    job_failure: 1,
 | 
				
			||||||
    failed_by_missing_dependency: 2, # This will be done in the next MR.
 | 
					    api_failure: 2,
 | 
				
			||||||
    failed_by_system: 3, # TODO: Not used. What's this state?
 | 
					    stuck_or_timeout_failure: 3,
 | 
				
			||||||
    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
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  state_machine :status do
 | 
					  state_machine :status do
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -53,7 +53,7 @@ module Projects
 | 
				
			||||||
      log_error("Projects::UpdatePagesService: #{message}")
 | 
					      log_error("Projects::UpdatePagesService: #{message}")
 | 
				
			||||||
      @status.allow_failure = !latest?
 | 
					      @status.allow_failure = !latest?
 | 
				
			||||||
      @status.description = message
 | 
					      @status.description = message
 | 
				
			||||||
      @status.drop(:failed_by_page)
 | 
					      @status.drop(:job_failure)
 | 
				
			||||||
      super
 | 
					      super
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -53,7 +53,7 @@ class StuckCiJobsWorker
 | 
				
			||||||
  def drop_build(type, build, status, timeout)
 | 
					  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})"
 | 
					    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|
 | 
					    Gitlab::OptimisticLocking.retry_lock(build, 3) do |b|
 | 
				
			||||||
      b.drop(:failed_by_stuck_and_timeout)
 | 
					      b.drop(:stuck_or_timeout_failure)
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -103,7 +103,7 @@ module API
 | 
				
			||||||
          when 'success'
 | 
					          when 'success'
 | 
				
			||||||
            status.success!
 | 
					            status.success!
 | 
				
			||||||
          when 'failed'
 | 
					          when 'failed'
 | 
				
			||||||
            status.drop!(:failed_by_api)
 | 
					            status.drop!(:api_failure)
 | 
				
			||||||
          when 'canceled'
 | 
					          when 'canceled'
 | 
				
			||||||
            status.cancel!
 | 
					            status.cancel!
 | 
				
			||||||
          else
 | 
					          else
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -127,7 +127,7 @@ module API
 | 
				
			||||||
        when 'success'
 | 
					        when 'success'
 | 
				
			||||||
          job.success
 | 
					          job.success
 | 
				
			||||||
        when 'failed'
 | 
					        when 'failed'
 | 
				
			||||||
          job.drop(:failed_job_state)
 | 
					          job.drop(:job_failure)
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1710,24 +1710,4 @@ describe Ci::Build do
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    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
 | 
					end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -443,4 +443,24 @@ describe CommitStatus do
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    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
 | 
					end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -143,7 +143,7 @@ describe API::CommitStatuses do
 | 
				
			||||||
              expect(json_response['target_url']).to be_nil
 | 
					              expect(json_response['target_url']).to be_nil
 | 
				
			||||||
              expect(json_response['description']).to be_nil
 | 
					              expect(json_response['description']).to be_nil
 | 
				
			||||||
              if status == 'failed'
 | 
					              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
 | 
					            end
 | 
				
			||||||
          end
 | 
					          end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -627,14 +627,14 @@ describe API::Runner do
 | 
				
			||||||
          update_job(state: 'success')
 | 
					          update_job(state: 'success')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          expect(job.reload.status).to eq 'success'
 | 
					          expect(job.reload.status).to eq 'success'
 | 
				
			||||||
          expect(job).to be_no_error
 | 
					          expect(job).to be_unknown_failure
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        it 'mark job as failed' do
 | 
					        it 'mark job as failed' do
 | 
				
			||||||
          update_job(state: 'failed')
 | 
					          update_job(state: 'failed')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          expect(job.reload.status).to eq 'failed'
 | 
					          expect(job.reload.status).to eq 'failed'
 | 
				
			||||||
          expect(job).to be_failed_by_job_state
 | 
					          expect(job).to be_job_failure
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -116,7 +116,7 @@ describe Projects::UpdatePagesService do
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        expect(deploy_status.description)
 | 
					        expect(deploy_status.description)
 | 
				
			||||||
          .to match(/artifacts for pages are too large/)
 | 
					          .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
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20,7 +20,7 @@ describe StuckCiJobsWorker do
 | 
				
			||||||
    it 'changes status' do
 | 
					    it 'changes status' do
 | 
				
			||||||
      worker.perform
 | 
					      worker.perform
 | 
				
			||||||
      is_expected.to eq('failed')
 | 
					      is_expected.to eq('failed')
 | 
				
			||||||
      expect(job).to be_failed_by_stuck_and_timeout
 | 
					      expect(job).to be_stuck_or_timeout_failure
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue