Commit 3e7f3bc7 authored by Tomasz Maczukin's avatar Tomasz Maczukin

Refactor timeout selection mechanism

parent e75614e8
...@@ -124,7 +124,7 @@ module Ci ...@@ -124,7 +124,7 @@ module Ci
after_transition pending: :running do |build| after_transition pending: :running do |build|
build.used_timeout = build.timeout build.used_timeout = build.timeout
build.timeout_source = build.should_use_runner_timeout? ? 'Runner' : 'Project' build.timeout_source = build.timeout < build.project.build_timeout ? 'Runner' : 'Project'
build.save! build.save!
build.run_after_commit do build.run_after_commit do
...@@ -239,13 +239,7 @@ module Ci ...@@ -239,13 +239,7 @@ module Ci
end end
def timeout def timeout
return runner.maximum_job_timeout if should_use_runner_timeout? [project.build_timeout, runner&.maximum_job_timeout].compact.min
project.build_timeout
end
def should_use_runner_timeout?
!runner.nil? && runner.defines_maximum_job_timeout? && runner.maximum_job_timeout < project.build_timeout
end end
def triggered_by?(current_user) def triggered_by?(current_user)
......
...@@ -2036,6 +2036,52 @@ describe Ci::Build do ...@@ -2036,6 +2036,52 @@ describe Ci::Build do
end end
end end
describe 'state transition: pending: :running' do
let(:runner) { create(:ci_runner) }
let(:job) { create(:ci_build, :pending, runner: runner) }
before do
job.project.build_timeout = 1800
job.project.save!
end
shared_examples 'saves data on transition' do
it 'saves used_timeout and timeout_source on transition' do
expect(job.used_timeout).to be_nil
expect(job.timeout_source).to be_nil
job.run!
expect(job.used_timeout).to eq(expected_timeout)
expect(job.timeout_source).to eq(expected_timeout_source)
end
end
context 'when runner timeout overrides project timeout' do
let(:expected_timeout) { 900 }
let(:expected_timeout_source) { 'Runner' }
before do
runner.maximum_job_timeout = 900
runner.save!
end
it_behaves_like 'saves data on transition'
end
context "when runner timeout doesn't override project timeout" do
let(:expected_timeout) { 1800 }
let(:expected_timeout_source) { 'Project' }
before do
runner.maximum_job_timeout = 3600
runner.save!
end
it_behaves_like 'saves data on transition'
end
end
describe 'state transition: any => [:running]' do describe 'state transition: any => [:running]' do
shared_examples 'validation is active' do shared_examples 'validation is active' do
context 'when depended job has not been completed yet' do context 'when depended job has not been completed yet' do
......
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