diff options
author | Tomasz Maczukin <tomasz@maczukin.pl> | 2018-02-19 18:23:12 +0100 |
---|---|---|
committer | Tomasz Maczukin <tomasz@maczukin.pl> | 2018-03-28 13:55:46 +0200 |
commit | 834f473821b816515504abb7c6bc91ab2dee4450 (patch) | |
tree | 5559e17ce6cced507d87ea53729875059378df45 /spec | |
parent | 7b82f4bab1661d7f7e7cb044730c977329275240 (diff) | |
download | gitlab-ce-834f473821b816515504abb7c6bc91ab2dee4450.tar.gz |
Override project-defined timeout with runner-defined one
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/ci/build_spec.rb | 24 | ||||
-rw-r--r-- | spec/models/ci/runner_spec.rb | 18 | ||||
-rw-r--r-- | spec/requests/api/runner_spec.rb | 35 |
3 files changed, 76 insertions, 1 deletions
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 7d935cf8d76..d13421a107f 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -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 diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb index ab170e6351c..80d7cd92fdb 100644 --- a/spec/models/ci/runner_spec.rb +++ b/spec/models/ci/runner_spec.rb @@ -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') } diff --git a/spec/requests/api/runner_spec.rb b/spec/requests/api/runner_spec.rb index 8c8f4bb7018..3eb0e88d095 100644 --- a/spec/requests/api/runner_spec.rb +++ b/spec/requests/api/runner_spec.rb @@ -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) |