Commit 834f4738 authored by Tomasz Maczukin's avatar Tomasz Maczukin

Override project-defined timeout with runner-defined one

parent 7b82f4ba
......@@ -232,9 +232,16 @@ module Ci
end
def timeout
return runner.job_upper_timeout if should_use_runner_timeout
project.build_timeout
end
def should_use_runner_timeout
runner && runner.defines_job_upper_timeout? && runner.job_upper_timeout < project.build_timeout
end
private :should_use_runner_timeout
def triggered_by?(current_user)
user == current_user
end
......
......@@ -167,6 +167,10 @@ module Ci
end
end
def defines_job_upper_timeout?
job_upper_timeout && job_upper_timeout > 0
end
private
def cleanup_runner_queue
......
......@@ -1272,8 +1272,30 @@ describe Ci::Build do
describe 'project settings' do
describe '#timeout' do
set(:project2) { create(:project, :repository, group: group, build_timeout: 1000) }
set(:pipeline2) { create(:ci_pipeline, project: project2, sha: project2.commit.id, ref: project2.default_branch, status: 'success') }
let(:build) { create(:ci_build, :manual, pipeline: pipeline2) }
it 'returns project timeout configuration' do
expect(build.timeout).to eq(project.build_timeout)
expect(build.timeout).to eq(project2.build_timeout)
end
context 'when runner sets timeout to bigger value' do
let(:runner2) { create(:ci_runner, job_upper_timeout: 2000) }
let(:build) { create(:ci_build, :manual, pipeline: pipeline2, runner: runner2) }
it 'returns project timeout configuration' do
expect(build.timeout).to eq(project2.build_timeout)
end
end
context 'when runner sets timeout to smaller value' do
let(:runner2) { create(:ci_runner, job_upper_timeout: 500) }
let(:build) { create(:ci_build, :manual, pipeline: pipeline2, runner: runner2) }
it 'returns project timeout configuration' do
expect(build.timeout).to eq(runner2.job_upper_timeout)
end
end
end
......
......@@ -556,6 +556,24 @@ describe Ci::Runner do
end
end
describe '#defines_job_upper_timeout?' do
context 'when job upper timeout is specified' do
subject { create(:ci_runner, job_upper_timeout: 1234) }
it 'should return true' do
expect(subject.defines_job_upper_timeout?).to be_truthy
end
end
context 'when job upper timeout is not specified' do
subject { create(:ci_runner) }
it 'should return false' do
expect(subject.defines_job_upper_timeout?).to be_falsey
end
end
end
describe '.search' do
let(:runner) { create(:ci_runner, token: '123abc', description: 'test runner') }
......
......@@ -658,6 +658,41 @@ describe API::Runner do
end
end
end
describe 'timeout support' do
context 'when project specifies job timeout' do
let(:project) { create(:project, shared_runners_enabled: false, build_timeout: 1234) }
it 'contains info about timeout taken from project' do
request_job
expect(response).to have_gitlab_http_status(201)
expect(json_response['runner_info']).to include({ 'timeout' => 1234 })
end
context 'when runner specifies lower timeout' do
let(:runner) { create(:ci_runner, job_upper_timeout: 1000) }
it 'contains info about timeout overridden by runner' do
request_job
expect(response).to have_gitlab_http_status(201)
expect(json_response['runner_info']).to include({ 'timeout' => 1000 })
end
end
context 'when runner specifies bigger timeout' do
let(:runner) { create(:ci_runner, job_upper_timeout: 2000) }
it 'contains info about timeout not overridden by runner' do
request_job
expect(response).to have_gitlab_http_status(201)
expect(json_response['runner_info']).to include({ 'timeout' => 1234 })
end
end
end
end
end
def request_job(token = runner.token, **params)
......
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