2018-03-20 21:58:43 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Ci::BuildMetadata do
|
|
|
|
set(:user) { create(:user) }
|
|
|
|
set(:group) { create(:group, :access_requestable) }
|
|
|
|
set(:project) { create(:project, :repository, group: group, build_timeout: 2000) }
|
|
|
|
|
|
|
|
set(:pipeline) do
|
|
|
|
create(:ci_pipeline, project: project,
|
|
|
|
sha: project.commit.id,
|
|
|
|
ref: project.default_branch,
|
|
|
|
status: 'success')
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:build) { create(:ci_build, pipeline: pipeline) }
|
2018-04-03 10:58:27 -04:00
|
|
|
let(:build_metadata) { build.metadata }
|
2018-03-20 21:58:43 -04:00
|
|
|
|
2018-03-26 11:47:46 -04:00
|
|
|
describe '#update_timeout_state' do
|
2018-03-20 21:58:43 -04:00
|
|
|
subject { build_metadata }
|
|
|
|
|
|
|
|
context 'when runner is not assigned to the job' do
|
|
|
|
it "doesn't change timeout value" do
|
2018-03-26 11:47:46 -04:00
|
|
|
expect { subject.update_timeout_state }.not_to change { subject.reload.timeout }
|
2018-03-20 21:58:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't change timeout_source value" do
|
2018-03-26 11:47:46 -04:00
|
|
|
expect { subject.update_timeout_state }.not_to change { subject.reload.timeout_source }
|
2018-03-20 21:58:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when runner is assigned to the job' do
|
|
|
|
before do
|
|
|
|
build.update_attributes(runner: runner)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when runner timeout is lower than project timeout' do
|
|
|
|
let(:runner) { create(:ci_runner, maximum_timeout: 1900) }
|
|
|
|
|
|
|
|
it 'sets runner timeout' do
|
2018-03-26 11:47:46 -04:00
|
|
|
expect { subject.update_timeout_state }.to change { subject.reload.timeout }.to(1900)
|
2018-03-20 21:58:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets runner_timeout_source' do
|
2018-03-26 11:47:46 -04:00
|
|
|
expect { subject.update_timeout_state }.to change { subject.reload.timeout_source }.to('runner_timeout_source')
|
2018-03-20 21:58:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when runner timeout is higher than project timeout' do
|
|
|
|
let(:runner) { create(:ci_runner, maximum_timeout: 2100) }
|
|
|
|
|
|
|
|
it 'sets project timeout' do
|
2018-03-26 11:47:46 -04:00
|
|
|
expect { subject.update_timeout_state }.to change { subject.reload.timeout }.to(2000)
|
2018-03-20 21:58:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets project_timeout_source' do
|
2018-03-26 11:47:46 -04:00
|
|
|
expect { subject.update_timeout_state }.to change { subject.reload.timeout_source }.to('project_timeout_source')
|
2018-03-20 21:58:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|