diff options
author | Tomasz Maczukin <tomasz@maczukin.pl> | 2018-03-26 17:47:46 +0200 |
---|---|---|
committer | Tomasz Maczukin <tomasz@maczukin.pl> | 2018-03-28 14:00:04 +0200 |
commit | 7008ed1e33bff510126a0eb0e4f7bf1a7adb02bd (patch) | |
tree | 7589748722a5a16dd08987acea99b3702b17b095 /spec/models/ci | |
parent | c2bc153314f14566abfdcbf92020cff41fc05a7e (diff) | |
download | gitlab-ce-7008ed1e33bff510126a0eb0e4f7bf1a7adb02bd.tar.gz |
Change and rename behavior of save_timeout_state!
Diffstat (limited to 'spec/models/ci')
-rw-r--r-- | spec/models/ci/build_metadata_spec.rb | 14 | ||||
-rw-r--r-- | spec/models/ci/build_spec.rb | 23 |
2 files changed, 30 insertions, 7 deletions
diff --git a/spec/models/ci/build_metadata_spec.rb b/spec/models/ci/build_metadata_spec.rb index d21e9600e42..268561ee941 100644 --- a/spec/models/ci/build_metadata_spec.rb +++ b/spec/models/ci/build_metadata_spec.rb @@ -15,16 +15,16 @@ describe Ci::BuildMetadata do let(:build) { create(:ci_build, pipeline: pipeline) } let(:build_metadata) { create(:ci_build_metadata, build: build) } - describe '#save_timeout_state!' do + describe '#update_timeout_state' do subject { build_metadata } context 'when runner is not assigned to the job' do it "doesn't change timeout value" do - expect { subject.save_timeout_state! }.not_to change { subject.reload.timeout } + expect { subject.update_timeout_state }.not_to change { subject.reload.timeout } end it "doesn't change timeout_source value" do - expect { subject.save_timeout_state! }.not_to change { subject.reload.timeout_source } + expect { subject.update_timeout_state }.not_to change { subject.reload.timeout_source } end end @@ -37,11 +37,11 @@ describe Ci::BuildMetadata do let(:runner) { create(:ci_runner, maximum_timeout: 1900) } it 'sets runner timeout' do - expect { subject.save_timeout_state! }.to change { subject.reload.timeout }.to(1900) + expect { subject.update_timeout_state }.to change { subject.reload.timeout }.to(1900) end it 'sets runner_timeout_source' do - expect { subject.save_timeout_state! }.to change { subject.reload.timeout_source }.to('runner_timeout_source') + expect { subject.update_timeout_state }.to change { subject.reload.timeout_source }.to('runner_timeout_source') end end @@ -49,11 +49,11 @@ describe Ci::BuildMetadata do let(:runner) { create(:ci_runner, maximum_timeout: 2100) } it 'sets project timeout' do - expect { subject.save_timeout_state! }.to change { subject.reload.timeout }.to(2000) + expect { subject.update_timeout_state }.to change { subject.reload.timeout }.to(2000) end it 'sets project_timeout_source' do - expect { subject.save_timeout_state! }.to change { subject.reload.timeout_source }.to('project_timeout_source') + expect { subject.update_timeout_state }.to change { subject.reload.timeout_source }.to('project_timeout_source') end end end diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 14dec2d4fc9..920b2284eb1 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -2050,6 +2050,11 @@ describe Ci::Build do job.project.update_attribute(:build_timeout, 1800) end + def run_job_without_exception + job.run! + rescue StateMachines::InvalidTransition + end + shared_examples 'saves data on transition' do it 'saves timeout' do expect { job.run! }.to change { job.reload.ensure_metadata.timeout }.from(nil).to(expected_timeout) @@ -2058,6 +2063,24 @@ describe Ci::Build do it 'saves timeout_source' do expect { job.run! }.to change { job.reload.ensure_metadata.timeout_source }.from('unknown_timeout_source').to(expected_timeout_source) end + + context 'when Ci::BuildMetadata#update_timeout_state fails update' do + before do + allow_any_instance_of(Ci::BuildMetadata).to receive(:update_timeout_state).and_return(false) + end + + it "doesn't save timeout" do + expect { run_job_without_exception }.not_to change { job.reload.ensure_metadata.timeout_source } + end + + it "doesn't save timeout_source" do + expect { run_job_without_exception }.not_to change { job.reload.ensure_metadata.timeout_source } + end + + it 'raises an exception' do + expect { job.run! }.to raise_error(StateMachines::InvalidTransition) + end + end end context 'when runner timeout overrides project timeout' do |