Commit 6ecde007 authored by Tomasz Maczukin's avatar Tomasz Maczukin

Remove Ci::Build#timeout

parent 403decbb
...@@ -26,6 +26,8 @@ module Ci ...@@ -26,6 +26,8 @@ module Ci
has_one :metadata, class_name: 'Ci::BuildMetadata' has_one :metadata, class_name: 'Ci::BuildMetadata'
delegate :timeout, to: :metadata, prefix: true, allow_nil: true
# The "environment" field for builds is a String, and is the unexpanded name # The "environment" field for builds is a String, and is the unexpanded name
def persisted_environment def persisted_environment
@persisted_environment ||= Environment.find_by( @persisted_environment ||= Environment.find_by(
...@@ -241,10 +243,6 @@ module Ci ...@@ -241,10 +243,6 @@ module Ci
latest_builds.where('stage_idx < ?', stage_idx) latest_builds.where('stage_idx < ?', stage_idx)
end end
def timeout
ensure_metadata.timeout
end
def triggered_by?(current_user) def triggered_by?(current_user)
user == current_user user == current_user
end end
......
...@@ -1120,7 +1120,7 @@ module API ...@@ -1120,7 +1120,7 @@ module API
end end
class RunnerInfo < Grape::Entity class RunnerInfo < Grape::Entity
expose :timeout expose :metadata_timeout, as: :timeout
end end
class Step < Grape::Entity class Step < Grape::Entity
......
...@@ -14,7 +14,7 @@ module Gitlab ...@@ -14,7 +14,7 @@ module Gitlab
self.new(:script).tap do |step| self.new(:script).tap do |step|
step.script = job.options[:before_script].to_a + job.options[:script].to_a step.script = job.options[:before_script].to_a + job.options[:script].to_a
step.script = job.commands.split("\n") if step.script.empty? step.script = job.commands.split("\n") if step.script.empty?
step.timeout = job.timeout step.timeout = job.metadata_timeout
step.when = WHEN_ON_SUCCESS step.when = WHEN_ON_SUCCESS
end end
end end
...@@ -25,7 +25,7 @@ module Gitlab ...@@ -25,7 +25,7 @@ module Gitlab
self.new(:after_script).tap do |step| self.new(:after_script).tap do |step|
step.script = after_script step.script = after_script
step.timeout = job.timeout step.timeout = job.metadata_timeout
step.when = WHEN_ALWAYS step.when = WHEN_ALWAYS
step.allow_failure = true step.allow_failure = true
end end
......
...@@ -5,10 +5,14 @@ describe Gitlab::Ci::Build::Step do ...@@ -5,10 +5,14 @@ describe Gitlab::Ci::Build::Step do
shared_examples 'has correct script' do shared_examples 'has correct script' do
subject { described_class.from_commands(job) } subject { described_class.from_commands(job) }
before do
job.run!
end
it 'fabricates an object' do it 'fabricates an object' do
expect(subject.name).to eq(:script) expect(subject.name).to eq(:script)
expect(subject.script).to eq(script) expect(subject.script).to eq(script)
expect(subject.timeout).to eq(job.timeout) expect(subject.timeout).to eq(job.metadata_timeout)
expect(subject.when).to eq('on_success') expect(subject.when).to eq('on_success')
expect(subject.allow_failure).to be_falsey expect(subject.allow_failure).to be_falsey
end end
...@@ -47,6 +51,10 @@ describe Gitlab::Ci::Build::Step do ...@@ -47,6 +51,10 @@ describe Gitlab::Ci::Build::Step do
subject { described_class.from_after_script(job) } subject { described_class.from_after_script(job) }
before do
job.run!
end
context 'when after_script is empty' do context 'when after_script is empty' do
it 'doesn not fabricate an object' do it 'doesn not fabricate an object' do
is_expected.to be_nil is_expected.to be_nil
...@@ -59,7 +67,7 @@ describe Gitlab::Ci::Build::Step do ...@@ -59,7 +67,7 @@ describe Gitlab::Ci::Build::Step do
it 'fabricates an object' do it 'fabricates an object' do
expect(subject.name).to eq(:after_script) expect(subject.name).to eq(:after_script)
expect(subject.script).to eq(['ls -la', 'date']) expect(subject.script).to eq(['ls -la', 'date'])
expect(subject.timeout).to eq(job.timeout) expect(subject.timeout).to eq(job.metadata_timeout)
expect(subject.when).to eq('always') expect(subject.when).to eq('always')
expect(subject.allow_failure).to be_truthy expect(subject.allow_failure).to be_truthy
end end
......
...@@ -1271,43 +1271,6 @@ describe Ci::Build do ...@@ -1271,43 +1271,6 @@ describe Ci::Build do
end end
describe 'project settings' 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, :pending, pipeline: pipeline2) }
subject { build.timeout }
before do
build.run!
end
context 'when runner is not assigned' do
it 'returns project timeout configuration' do
is_expected.to be_nil
end
end
context 'when runner sets timeout to bigger value' do
let(:runner2) { create(:ci_runner, maximum_timeout: 2000) }
let(:build) { create(:ci_build, :pending, pipeline: pipeline2, runner: runner2) }
it 'returns project timeout configuration' do
is_expected.to eq(project2.build_timeout)
end
end
context 'when runner sets timeout to smaller value' do
let(:runner2) { create(:ci_runner, maximum_timeout: 600) }
let(:build) { create(:ci_build, :pending, pipeline: pipeline2, runner: runner2) }
it 'returns project timeout configuration' do
is_expected.to eq(runner2.maximum_timeout)
end
end
end
describe '#allow_git_fetch' do describe '#allow_git_fetch' do
it 'return project allow_git_fetch configuration' do it 'return project allow_git_fetch configuration' do
expect(build.allow_git_fetch).to eq(project.build_allow_git_fetch) expect(build.allow_git_fetch).to eq(project.build_allow_git_fetch)
......
...@@ -360,12 +360,12 @@ describe API::Runner do ...@@ -360,12 +360,12 @@ describe API::Runner do
let(:expected_steps) do let(:expected_steps) do
[{ 'name' => 'script', [{ 'name' => 'script',
'script' => %w(ls date), 'script' => %w(ls date),
'timeout' => job.timeout, 'timeout' => job.metadata_timeout,
'when' => 'on_success', 'when' => 'on_success',
'allow_failure' => false }, 'allow_failure' => false },
{ 'name' => 'after_script', { 'name' => 'after_script',
'script' => %w(ls date), 'script' => %w(ls date),
'timeout' => job.timeout, 'timeout' => job.metadata_timeout,
'when' => 'always', 'when' => 'always',
'allow_failure' => true }] 'allow_failure' => true }]
end end
......
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