diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-16 21:06:05 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-16 21:06:05 +0300 |
commit | 930ff68c1efc380cb7522aa9b3884842eecb2486 (patch) | |
tree | 208f21205f9c8ee90e9722c6f641169d9a1569bf /spec | |
parent | 84727c8209a4412e21111a07f99b0438b03232de (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/ci/build/step_spec.rb | 52 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/job_spec.rb | 31 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/yaml_processor_spec.rb | 42 | ||||
-rw-r--r-- | spec/lib/gitlab/hook_data/issuable_builder_spec.rb | 18 | ||||
-rw-r--r-- | spec/models/ci/build_metadata_spec.rb | 70 | ||||
-rw-r--r-- | spec/models/concerns/routable_spec.rb | 20 | ||||
-rw-r--r-- | spec/services/ci/create_pipeline_service_spec.rb | 16 |
7 files changed, 188 insertions, 61 deletions
diff --git a/spec/lib/gitlab/ci/build/step_spec.rb b/spec/lib/gitlab/ci/build/step_spec.rb index 84e6e0e177f..9c1a8cf5e91 100644 --- a/spec/lib/gitlab/ci/build/step_spec.rb +++ b/spec/lib/gitlab/ci/build/step_spec.rb @@ -4,39 +4,49 @@ require 'spec_helper' describe Gitlab::Ci::Build::Step do describe '#from_commands' do - shared_examples 'has correct script' do - subject { described_class.from_commands(job) } + subject { described_class.from_commands(job) } - before do - job.run! - end + before do + job.run! + end + shared_examples 'has correct script' do it 'fabricates an object' do expect(subject.name).to eq(:script) expect(subject.script).to eq(script) - expect(subject.timeout).to eq(job.metadata_timeout) expect(subject.when).to eq('on_success') expect(subject.allow_failure).to be_falsey end end context 'when script option is specified' do - it_behaves_like 'has correct script' do - let(:job) { create(:ci_build, :no_options, options: { script: ["ls -la\necho aaa", "date"] }) } - let(:script) { ["ls -la\necho aaa", 'date'] } - end + let(:job) { create(:ci_build, :no_options, options: { script: ["ls -la\necho aaa", "date"] }) } + let(:script) { ["ls -la\necho aaa", 'date'] } + + it_behaves_like 'has correct script' end context 'when before and script option is specified' do - it_behaves_like 'has correct script' do - let(:job) do - create(:ci_build, options: { - before_script: ["ls -la\necho aaa"], - script: ["date"] - }) - end - - let(:script) { ["ls -la\necho aaa", 'date'] } + let(:job) do + create(:ci_build, options: { + before_script: ["ls -la\necho aaa"], + script: ["date"] + }) + end + + let(:script) { ["ls -la\necho aaa", 'date'] } + + it_behaves_like 'has correct script' + end + + context 'when timeout option is specified in seconds' do + let(:job) { create(:ci_build, options: { job_timeout: 3, script: ["ls -la\necho aaa", 'date'] }) } + let(:script) { ["ls -la\necho aaa", 'date'] } + + it_behaves_like 'has correct script' + + it 'has job level timeout' do + expect(subject.timeout).to eq(3) end end end @@ -57,12 +67,12 @@ describe Gitlab::Ci::Build::Step do end context 'when after_script is not empty' do - let(:job) { create(:ci_build, options: { script: ['bash'], after_script: ['ls -la', 'date'] }) } + let(:job) { create(:ci_build, options: { job_timeout: 60, script: ['bash'], after_script: ['ls -la', 'date'] }) } it 'fabricates an object' do expect(subject.name).to eq(:after_script) expect(subject.script).to eq(['ls -la', 'date']) - expect(subject.timeout).to eq(job.metadata_timeout) + expect(subject.timeout).to eq(60) expect(subject.when).to eq('always') expect(subject.allow_failure).to be_truthy end diff --git a/spec/lib/gitlab/ci/config/entry/job_spec.rb b/spec/lib/gitlab/ci/config/entry/job_spec.rb index 1853efde350..1c4887e87c4 100644 --- a/spec/lib/gitlab/ci/config/entry/job_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/job_spec.rb @@ -417,6 +417,37 @@ describe Gitlab::Ci::Config::Entry::Job do end end end + + context 'when timeout value is not correct' do + context 'when it is higher than instance wide timeout' do + let(:config) { { timeout: '3 months' } } + + it 'returns error about value too high' do + expect(entry).not_to be_valid + expect(entry.errors) + .to include "job timeout should not exceed the limit" + end + end + + context 'when it is not a duration' do + let(:config) { { timeout: 100 } } + + it 'returns error about wrong value' do + expect(entry).not_to be_valid + expect(entry.errors).to include 'job timeout should be a duration' + end + end + end + + context 'when timeout value is correct' do + let(:config) { { script: 'echo', timeout: '1m 1s' } } + + it 'returns correct timeout' do + expect(entry).to be_valid + expect(entry.errors).to be_empty + expect(entry.timeout).to eq('1m 1s') + end + end end end diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb index 9d9a9ecda33..8f2f23f6110 100644 --- a/spec/lib/gitlab/ci/yaml_processor_spec.rb +++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb @@ -1134,6 +1134,48 @@ module Gitlab end end + describe "Timeout" do + let(:config) do + { + deploy_to_production: { + stage: 'deploy', + script: 'test' + } + } + end + + let(:processor) { Gitlab::Ci::YamlProcessor.new(YAML.dump(config)) } + let(:builds) { processor.stage_builds_attributes('deploy') } + + context 'when no timeout was provided' do + it 'does not include job_timeout' do + expect(builds.size).to eq(1) + expect(builds.first[:options]).not_to include(:job_timeout) + end + end + + context 'when an invalid timeout was provided' do + before do + config[:deploy_to_production][:timeout] = 'not-a-number' + end + + it 'raises an error for invalid number' do + expect { builds }.to raise_error('jobs:deploy_to_production timeout should be a duration') + end + end + + context 'when some valid timeout was provided' do + before do + config[:deploy_to_production][:timeout] = '1m 3s' + end + + it 'returns provided timeout value' do + expect(builds.size).to eq(1) + expect(builds.first[:options]).to include(job_timeout: 63) + end + end + end + describe "Dependencies" do let(:config) do { diff --git a/spec/lib/gitlab/hook_data/issuable_builder_spec.rb b/spec/lib/gitlab/hook_data/issuable_builder_spec.rb index 569d5dcc757..97a89b319ea 100644 --- a/spec/lib/gitlab/hook_data/issuable_builder_spec.rb +++ b/spec/lib/gitlab/hook_data/issuable_builder_spec.rb @@ -42,7 +42,15 @@ describe Gitlab::HookData::IssuableBuilder do [{ id: 1, title: 'foo' }], [{ id: 1, title: 'foo' }, { id: 2, title: 'bar' }] ], - total_time_spent: [1, 2] + total_time_spent: [1, 2], + assignees: [ + [], + [{ + name: "Foo Bar", + username: "foobar", + avatar_url: "http://www.example.com/my-avatar.jpg" + }] + ] } end let(:data) { builder.build(user: user, changes: changes) } @@ -58,6 +66,14 @@ describe Gitlab::HookData::IssuableBuilder do total_time_spent: { previous: 1, current: 2 + }, + assignees: { + previous: [], + current: [{ + name: "Foo Bar", + username: "foobar", + avatar_url: "http://www.example.com/my-avatar.jpg" + }] } })) end diff --git a/spec/models/ci/build_metadata_spec.rb b/spec/models/ci/build_metadata_spec.rb index 917a65ddf21..67cd939b4c6 100644 --- a/spec/models/ci/build_metadata_spec.rb +++ b/spec/models/ci/build_metadata_spec.rb @@ -22,42 +22,72 @@ describe Ci::BuildMetadata do describe '#update_timeout_state' do subject { metadata } - context 'when runner is not assigned to the job' do - it "doesn't change timeout value" do - expect { subject.update_timeout_state }.not_to change { subject.reload.timeout } + shared_examples 'sets timeout' do |source, timeout| + it 'sets project_timeout_source' do + expect { subject.update_timeout_state }.to change { subject.reload.timeout_source }.to(source) end - it "doesn't change timeout_source value" do - expect { subject.update_timeout_state }.not_to change { subject.reload.timeout_source } + it 'sets project timeout' do + expect { subject.update_timeout_state }.to change { subject.reload.timeout }.to(timeout) end end - context 'when runner is assigned to the job' do - before do - build.update(runner: runner) + context 'when project timeout is set' do + context 'when runner is assigned to the job' do + before do + build.update!(runner: runner) + end + + context 'when runner timeout is not set' do + let(:runner) { create(:ci_runner, maximum_timeout: nil) } + + it_behaves_like 'sets timeout', 'project_timeout_source', 2000 + end + + context 'when runner timeout is lower than project timeout' do + let(:runner) { create(:ci_runner, maximum_timeout: 1900) } + + it_behaves_like 'sets timeout', 'runner_timeout_source', 1900 + end + + context 'when runner timeout is higher than project timeout' do + let(:runner) { create(:ci_runner, maximum_timeout: 2100) } + + it_behaves_like 'sets timeout', 'project_timeout_source', 2000 + end end - context 'when runner timeout is lower than project timeout' do - let(:runner) { create(:ci_runner, maximum_timeout: 1900) } + context 'when job timeout is set' do + context 'when job timeout is higher than project timeout' do + let(:build) { create(:ci_build, pipeline: pipeline, options: { job_timeout: 3000 }) } - it 'sets runner timeout' do - expect { subject.update_timeout_state }.to change { subject.reload.timeout }.to(1900) + it_behaves_like 'sets timeout', 'job_timeout_source', 3000 end - it 'sets runner_timeout_source' do - expect { subject.update_timeout_state }.to change { subject.reload.timeout_source }.to('runner_timeout_source') + context 'when job timeout is lower than project timeout' do + let(:build) { create(:ci_build, pipeline: pipeline, options: { job_timeout: 1000 }) } + + it_behaves_like 'sets timeout', 'job_timeout_source', 1000 end end - context 'when runner timeout is higher than project timeout' do - let(:runner) { create(:ci_runner, maximum_timeout: 2100) } + context 'when both runner and job timeouts are set' do + before do + build.update(runner: runner) + end + + context 'when job timeout is higher than runner timeout' do + let(:build) { create(:ci_build, pipeline: pipeline, options: { job_timeout: 3000 }) } + let(:runner) { create(:ci_runner, maximum_timeout: 2100) } - it 'sets project timeout' do - expect { subject.update_timeout_state }.to change { subject.reload.timeout }.to(2000) + it_behaves_like 'sets timeout', 'runner_timeout_source', 2100 end - it 'sets project_timeout_source' do - expect { subject.update_timeout_state }.to change { subject.reload.timeout_source }.to('project_timeout_source') + context 'when job timeout is lower than runner timeout' do + let(:build) { create(:ci_build, pipeline: pipeline, options: { job_timeout: 1900 }) } + let(:runner) { create(:ci_runner, maximum_timeout: 2100) } + + it_behaves_like 'sets timeout', 'job_timeout_source', 1900 end end end diff --git a/spec/models/concerns/routable_spec.rb b/spec/models/concerns/routable_spec.rb index cad705ee594..f78a089bc2e 100644 --- a/spec/models/concerns/routable_spec.rb +++ b/spec/models/concerns/routable_spec.rb @@ -58,7 +58,7 @@ describe Group, 'Routable' do end end - shared_examples_for '.find_by_full_path' do + context '.find_by_full_path' do let!(:nested_group) { create(:group, parent: group) } context 'without any redirect routes' do @@ -117,24 +117,6 @@ describe Group, 'Routable' do end end - describe '.find_by_full_path' do - context 'with routable_two_step_lookup feature' do - before do - stub_feature_flags(routable_two_step_lookup: true) - end - - it_behaves_like '.find_by_full_path' - end - - context 'without routable_two_step_lookup feature' do - before do - stub_feature_flags(routable_two_step_lookup: false) - end - - it_behaves_like '.find_by_full_path' - end - end - describe '.where_full_path_in' do context 'without any paths' do it 'returns an empty relation' do diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index 19cc2ddf7db..6eafe122697 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -795,6 +795,22 @@ describe Ci::CreatePipelineService do end end + context 'with timeout' do + context 'when builds with custom timeouts are configured' do + before do + config = YAML.dump(rspec: { script: 'rspec', timeout: '2m 3s' }) + stub_ci_pipeline_yaml_file(config) + end + + it 'correctly creates builds with custom timeout value configured' do + pipeline = execute_service + + expect(pipeline).to be_persisted + expect(pipeline.builds.find_by(name: 'rspec').options[:job_timeout]).to eq 123 + end + end + end + shared_examples 'when ref is protected' do let(:user) { create(:user) } |