diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-24 15:08:01 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-24 15:08:01 +0300 |
commit | c6373a2cec855c6543a1e035c52099e102dd05ef (patch) | |
tree | 507c4d975e1bf559a008d997ad4b07dad14f397e /spec | |
parent | 6593f1f627938f22090dec5221476772d3ed581d (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
23 files changed, 445 insertions, 55 deletions
diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb index a38935c89ba..0c5d14eeb32 100644 --- a/spec/factories/ci/builds.rb +++ b/spec/factories/ci/builds.rb @@ -77,6 +77,10 @@ FactoryBot.define do status { 'created' } end + trait :waiting_for_resource do + status { 'waiting_for_resource' } + end + trait :preparing do status { 'preparing' } end diff --git a/spec/factories/commit_statuses.rb b/spec/factories/commit_statuses.rb index 5d635d93ff2..a54c0ce74c6 100644 --- a/spec/factories/commit_statuses.rb +++ b/spec/factories/commit_statuses.rb @@ -35,6 +35,10 @@ FactoryBot.define do status { 'pending' } end + trait :waiting_for_resource do + status { 'waiting_for_resource' } + end + trait :preparing do status { 'preparing' } end diff --git a/spec/features/projects/pipelines/pipeline_spec.rb b/spec/features/projects/pipelines/pipeline_spec.rb index 94fac9a2eb5..4b97c58d920 100644 --- a/spec/features/projects/pipelines/pipeline_spec.rb +++ b/spec/features/projects/pipelines/pipeline_spec.rb @@ -606,6 +606,117 @@ describe 'Pipeline', :js do end end + context 'when build requires resource', :sidekiq_inline do + let_it_be(:project) { create(:project, :repository) } + let(:pipeline) { create(:ci_pipeline, project: project) } + let(:resource_group) { create(:ci_resource_group, project: project) } + + let!(:test_job) do + create(:ci_build, :pending, stage: 'test', name: 'test', + stage_idx: 1, pipeline: pipeline, project: project) + end + + let!(:deploy_job) do + create(:ci_build, :created, stage: 'deploy', name: 'deploy', + stage_idx: 2, pipeline: pipeline, project: project, resource_group: resource_group) + end + + describe 'GET /:project/pipelines/:id' do + subject { visit project_pipeline_path(project, pipeline) } + + it 'shows deploy job as created' do + subject + + within('.pipeline-header-container') do + expect(page).to have_content('pending') + end + + within('.pipeline-graph') do + within '.stage-column:nth-child(1)' do + expect(page).to have_content('test') + expect(page).to have_css('.ci-status-icon-pending') + end + + within '.stage-column:nth-child(2)' do + expect(page).to have_content('deploy') + expect(page).to have_css('.ci-status-icon-created') + end + end + end + + context 'when test job succeeded' do + before do + test_job.success! + end + + it 'shows deploy job as pending' do + subject + + within('.pipeline-header-container') do + expect(page).to have_content('running') + end + + within('.pipeline-graph') do + within '.stage-column:nth-child(1)' do + expect(page).to have_content('test') + expect(page).to have_css('.ci-status-icon-success') + end + + within '.stage-column:nth-child(2)' do + expect(page).to have_content('deploy') + expect(page).to have_css('.ci-status-icon-pending') + end + end + end + end + + context 'when test job succeeded but there are no available resources' do + let(:another_job) { create(:ci_build, :running, project: project, resource_group: resource_group) } + + before do + resource_group.assign_resource_to(another_job) + test_job.success! + end + + it 'shows deploy job as waiting for resource' do + subject + + within('.pipeline-header-container') do + expect(page).to have_content('waiting') + end + + within('.pipeline-graph') do + within '.stage-column:nth-child(2)' do + expect(page).to have_content('deploy') + expect(page).to have_css('.ci-status-icon-waiting-for-resource') + end + end + end + + context 'when resource is released from another job' do + before do + another_job.success! + end + + it 'shows deploy job as pending' do + subject + + within('.pipeline-header-container') do + expect(page).to have_content('running') + end + + within('.pipeline-graph') do + within '.stage-column:nth-child(2)' do + expect(page).to have_content('deploy') + expect(page).to have_css('.ci-status-icon-pending') + end + end + end + end + end + end + end + describe 'GET /:project/pipelines/:id/builds' do include_context 'pipeline builds' diff --git a/spec/frontend/lib/utils/datetime_utility_spec.js b/spec/frontend/lib/utils/datetime_utility_spec.js index 872779299d2..c32710196db 100644 --- a/spec/frontend/lib/utils/datetime_utility_spec.js +++ b/spec/frontend/lib/utils/datetime_utility_spec.js @@ -341,6 +341,16 @@ describe('prettyTime methods', () => { assertTimeUnits(twoDays, 3, 48, 0, 0); }); + + it('should correctly parse values when limitedToDays is true', () => { + const sevenDays = datetimeUtility.parseSeconds(648750, { + hoursPerDay: 24, + daysPerWeek: 7, + limitToDays: true, + }); + + assertTimeUnits(sevenDays, 12, 12, 7, 0); + }); }); describe('stringifyTime', () => { @@ -507,3 +517,32 @@ describe('secondsToDays', () => { expect(datetimeUtility.secondsToDays(270000)).toBe(3); }); }); + +describe('approximateDuration', () => { + it.each` + seconds + ${null} + ${{}} + ${[]} + ${-1} + `('returns a blank string for seconds=$seconds', ({ seconds }) => { + expect(datetimeUtility.approximateDuration(seconds)).toBe(''); + }); + + it.each` + seconds | approximation + ${0} | ${'less than a minute'} + ${25} | ${'less than a minute'} + ${45} | ${'1 minute'} + ${90} | ${'1 minute'} + ${100} | ${'1 minute'} + ${150} | ${'2 minutes'} + ${220} | ${'3 minutes'} + ${3000} | ${'about 1 hour'} + ${30000} | ${'about 8 hours'} + ${100000} | ${'1 day'} + ${180000} | ${'2 days'} + `('converts $seconds seconds to $approximation', ({ seconds, approximation }) => { + expect(datetimeUtility.approximateDuration(seconds)).toBe(approximation); + }); +}); diff --git a/spec/lib/banzai/filter/plantuml_filter_spec.rb b/spec/lib/banzai/filter/plantuml_filter_spec.rb index 713bab4527b..abe525ac47a 100644 --- a/spec/lib/banzai/filter/plantuml_filter_spec.rb +++ b/spec/lib/banzai/filter/plantuml_filter_spec.rb @@ -26,7 +26,7 @@ describe Banzai::Filter::PlantumlFilter do it 'does not replace plantuml pre tag with img tag if url is invalid' do stub_application_setting(plantuml_enabled: true, plantuml_url: "invalid") input = '<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>' - output = '<div class="listingblock"><div class="content"><pre class="plantuml plantuml-error"> PlantUML Error: cannot connect to PlantUML server at "invalid"</pre></div></div>' + output = '<div class="listingblock"><div class="content"><pre class="plantuml plantuml-error"> Error: cannot connect to PlantUML server at "invalid"</pre></div></div>' doc = filter(input) expect(doc.to_s).to eq output diff --git a/spec/lib/gitlab/ci/status/external/factory_spec.rb b/spec/lib/gitlab/ci/status/external/factory_spec.rb index 9d7dfc42848..9c11e42fc5a 100644 --- a/spec/lib/gitlab/ci/status/external/factory_spec.rb +++ b/spec/lib/gitlab/ci/status/external/factory_spec.rb @@ -22,7 +22,7 @@ describe Gitlab::Ci::Status::External::Factory do end let(:expected_status) do - Gitlab::Ci::Status.const_get(simple_status.capitalize, false) + Gitlab::Ci::Status.const_get(simple_status.to_s.camelize, false) end it "fabricates a core status #{simple_status}" do diff --git a/spec/lib/gitlab/ci/status/factory_spec.rb b/spec/lib/gitlab/ci/status/factory_spec.rb index c6d7a1ec5d9..219eb53d9df 100644 --- a/spec/lib/gitlab/ci/status/factory_spec.rb +++ b/spec/lib/gitlab/ci/status/factory_spec.rb @@ -13,7 +13,7 @@ describe Gitlab::Ci::Status::Factory do let(:resource) { double('resource', status: simple_status) } let(:expected_status) do - Gitlab::Ci::Status.const_get(simple_status.capitalize, false) + Gitlab::Ci::Status.const_get(simple_status.to_s.camelize, false) end it "fabricates a core status #{simple_status}" do diff --git a/spec/lib/gitlab/ci/status/pipeline/factory_spec.rb b/spec/lib/gitlab/ci/status/pipeline/factory_spec.rb index 3acc767ab7a..838154759cb 100644 --- a/spec/lib/gitlab/ci/status/pipeline/factory_spec.rb +++ b/spec/lib/gitlab/ci/status/pipeline/factory_spec.rb @@ -18,7 +18,7 @@ describe Gitlab::Ci::Status::Pipeline::Factory do let(:pipeline) { create(:ci_pipeline, status: simple_status) } let(:expected_status) do - Gitlab::Ci::Status.const_get(simple_status.capitalize, false) + Gitlab::Ci::Status.const_get(simple_status.camelize, false) end it "matches correct core status for #{simple_status}" do diff --git a/spec/lib/gitlab/ci/status/stage/factory_spec.rb b/spec/lib/gitlab/ci/status/stage/factory_spec.rb index dcb53712157..317756ea13c 100644 --- a/spec/lib/gitlab/ci/status/stage/factory_spec.rb +++ b/spec/lib/gitlab/ci/status/stage/factory_spec.rb @@ -34,7 +34,7 @@ describe Gitlab::Ci::Status::Stage::Factory do it "fabricates a core status #{core_status}" do expect(status).to be_a( - Gitlab::Ci::Status.const_get(core_status.capitalize, false)) + Gitlab::Ci::Status.const_get(core_status.camelize, false)) end it 'extends core status with common stage methods' do diff --git a/spec/lib/gitlab/ci/status/waiting_for_resource_spec.rb b/spec/lib/gitlab/ci/status/waiting_for_resource_spec.rb new file mode 100644 index 00000000000..ed00dac8560 --- /dev/null +++ b/spec/lib/gitlab/ci/status/waiting_for_resource_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Ci::Status::WaitingForResource do + subject do + described_class.new(double('subject'), double('user')) + end + + describe '#text' do + it { expect(subject.text).to eq 'waiting' } + end + + describe '#label' do + it { expect(subject.label).to eq 'waiting for resource' } + end + + describe '#icon' do + it { expect(subject.icon).to eq 'status_pending' } + end + + describe '#favicon' do + it { expect(subject.favicon).to eq 'favicon_pending' } + end + + describe '#group' do + it { expect(subject.group).to eq 'waiting-for-resource' } + end +end diff --git a/spec/lib/gitlab/git/branch_spec.rb b/spec/lib/gitlab/git/branch_spec.rb index cc26b7e7fcd..cb3f4df2dbd 100644 --- a/spec/lib/gitlab/git/branch_spec.rb +++ b/spec/lib/gitlab/git/branch_spec.rb @@ -71,9 +71,7 @@ describe Gitlab::Git::Branch, :seed_helper do end let(:user) { create(:user) } - let(:committer) do - Gitlab::Git.committer_hash(email: user.email, name: user.name) - end + let(:committer) { { email: user.email, name: user.name } } let(:params) do parents = [rugged.head.target] tree = parents.first.tree diff --git a/spec/lib/gitlab/git_spec.rb b/spec/lib/gitlab/git_spec.rb index cb07bbdbaaa..d6d12b84724 100644 --- a/spec/lib/gitlab/git_spec.rb +++ b/spec/lib/gitlab/git_spec.rb @@ -6,32 +6,6 @@ describe Gitlab::Git do let(:committer_email) { 'user@example.org' } let(:committer_name) { 'John Doe' } - describe 'committer_hash' do - it "returns a hash containing the given email and name" do - committer_hash = described_class.committer_hash(email: committer_email, name: committer_name) - - expect(committer_hash[:email]).to eq(committer_email) - expect(committer_hash[:name]).to eq(committer_name) - expect(committer_hash[:time]).to be_a(Time) - end - - context 'when email is nil' do - it "returns nil" do - committer_hash = described_class.committer_hash(email: nil, name: committer_name) - - expect(committer_hash).to be_nil - end - end - - context 'when name is nil' do - it "returns nil" do - committer_hash = described_class.committer_hash(email: committer_email, name: nil) - - expect(committer_hash).to be_nil - end - end - end - describe '.ref_name' do it 'ensure ref is a valid UTF-8 string' do utf8_invalid_ref = Gitlab::Git::BRANCH_REF_PREFIX + "an_invalid_ref_\xE5" diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index f9c17f732b6..5fabdd9c6c5 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1119,6 +1119,60 @@ describe Ci::Build do end end + describe 'state transition with resource group' do + let(:resource_group) { create(:ci_resource_group, project: project) } + + context 'when build status is created' do + let(:build) { create(:ci_build, :created, project: project, resource_group: resource_group) } + + it 'is waiting for resource when build is enqueued' do + expect(Ci::ResourceGroups::AssignResourceFromResourceGroupWorker).to receive(:perform_async).with(resource_group.id) + + expect { build.enqueue! }.to change { build.status }.from('created').to('waiting_for_resource') + + expect(build.waiting_for_resource_at).not_to be_nil + end + + context 'when build is waiting for resource' do + before do + build.update_column(:status, 'waiting_for_resource') + end + + it 'is enqueued when build requests resource' do + expect { build.enqueue_waiting_for_resource! }.to change { build.status }.from('waiting_for_resource').to('pending') + end + + it 'releases a resource when build finished' do + expect(build.resource_group).to receive(:release_resource_from).with(build).and_call_original + expect(Ci::ResourceGroups::AssignResourceFromResourceGroupWorker).to receive(:perform_async).with(build.resource_group_id) + + build.enqueue_waiting_for_resource! + build.success! + end + + context 'when build has prerequisites' do + before do + allow(build).to receive(:any_unmet_prerequisites?) { true } + end + + it 'is preparing when build is enqueued' do + expect { build.enqueue_waiting_for_resource! }.to change { build.status }.from('waiting_for_resource').to('preparing') + end + end + + context 'when there are no available resources' do + before do + resource_group.assign_resource_to(create(:ci_build)) + end + + it 'stays as waiting for resource when build requests resource' do + expect { build.enqueue_waiting_for_resource }.not_to change { build.status } + end + end + end + end + end + describe '#on_stop' do subject { build.on_stop } diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 286d2ac4fe6..b30e88532e1 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -1750,7 +1750,7 @@ describe Ci::Pipeline, :mailer do subject { described_class.bridgeable_statuses } it { is_expected.to be_an(Array) } - it { is_expected.not_to include('created', 'preparing', 'pending') } + it { is_expected.not_to include('created', 'waiting_for_resource', 'preparing', 'pending') } end describe '#status', :sidekiq_might_not_need_inline do @@ -1760,6 +1760,17 @@ describe Ci::Pipeline, :mailer do subject { pipeline.reload.status } + context 'on waiting for resource' do + before do + allow(build).to receive(:requires_resource?) { true } + allow(Ci::ResourceGroups::AssignResourceFromResourceGroupWorker).to receive(:perform_async) + + build.enqueue + end + + it { is_expected.to eq('waiting_for_resource') } + end + context 'on prepare' do before do # Prevent skipping directly to 'pending' diff --git a/spec/models/ci/stage_spec.rb b/spec/models/ci/stage_spec.rb index b65c11f837c..7e2751128e2 100644 --- a/spec/models/ci/stage_spec.rb +++ b/spec/models/ci/stage_spec.rb @@ -105,6 +105,18 @@ describe Ci::Stage, :models do end end + context 'when build is waiting for resource' do + before do + create(:ci_build, :waiting_for_resource, stage_id: stage.id) + end + + it 'updates status to waiting for resource' do + expect { stage.update_status } + .to change { stage.reload.status } + .to 'waiting_for_resource' + end + end + context 'when stage is skipped because is empty' do it 'updates status to skipped' do expect { stage.update_status } diff --git a/spec/models/commit_status_spec.rb b/spec/models/commit_status_spec.rb index 31aebac54e1..98dc6f00412 100644 --- a/spec/models/commit_status_spec.rb +++ b/spec/models/commit_status_spec.rb @@ -634,6 +634,30 @@ describe CommitStatus do end end + describe '#all_met_to_become_pending?' do + subject { commit_status.all_met_to_become_pending? } + + let(:commit_status) { create(:commit_status) } + + it { is_expected.to eq(true) } + + context 'when build requires a resource' do + before do + allow(commit_status).to receive(:requires_resource?) { true } + end + + it { is_expected.to eq(false) } + end + + context 'when build has a prerequisite' do + before do + allow(commit_status).to receive(:any_unmet_prerequisites?) { true } + end + + it { is_expected.to eq(false) } + end + end + describe '#enqueue' do let!(:current_time) { Time.new(2018, 4, 5, 14, 0, 0) } @@ -654,12 +678,6 @@ describe CommitStatus do it_behaves_like 'commit status enqueued' end - context 'when initial state is :preparing' do - let(:commit_status) { create(:commit_status, :preparing) } - - it_behaves_like 'commit status enqueued' - end - context 'when initial state is :skipped' do let(:commit_status) { create(:commit_status, :skipped) } diff --git a/spec/models/concerns/has_status_spec.rb b/spec/models/concerns/has_status_spec.rb index 21e4dda6dab..99d09af80d0 100644 --- a/spec/models/concerns/has_status_spec.rb +++ b/spec/models/concerns/has_status_spec.rb @@ -39,6 +39,22 @@ describe HasStatus do it { is_expected.to eq 'running' } end + context 'all waiting for resource' do + let!(:statuses) do + [create(type, status: :waiting_for_resource), create(type, status: :waiting_for_resource)] + end + + it { is_expected.to eq 'waiting_for_resource' } + end + + context 'at least one waiting for resource' do + let!(:statuses) do + [create(type, status: :success), create(type, status: :waiting_for_resource)] + end + + it { is_expected.to eq 'waiting_for_resource' } + end + context 'all preparing' do let!(:statuses) do [create(type, status: :preparing), create(type, status: :preparing)] @@ -219,7 +235,7 @@ describe HasStatus do end end - %i[created preparing running pending success + %i[created waiting_for_resource preparing running pending success failed canceled skipped].each do |status| it_behaves_like 'having a job', status end @@ -265,7 +281,7 @@ describe HasStatus do describe '.alive' do subject { CommitStatus.alive } - %i[running pending preparing created].each do |status| + %i[running pending waiting_for_resource preparing created].each do |status| it_behaves_like 'containing the job', status end @@ -277,7 +293,7 @@ describe HasStatus do describe '.alive_or_scheduled' do subject { CommitStatus.alive_or_scheduled } - %i[running pending preparing created scheduled].each do |status| + %i[running pending waiting_for_resource preparing created scheduled].each do |status| it_behaves_like 'containing the job', status end @@ -313,7 +329,7 @@ describe HasStatus do describe '.cancelable' do subject { CommitStatus.cancelable } - %i[running pending preparing created scheduled].each do |status| + %i[running pending waiting_for_resource preparing created scheduled].each do |status| it_behaves_like 'containing the job', status end diff --git a/spec/services/ci/prepare_build_service_spec.rb b/spec/services/ci/prepare_build_service_spec.rb index 3c3d8b90bb0..02928b58ff8 100644 --- a/spec/services/ci/prepare_build_service_spec.rb +++ b/spec/services/ci/prepare_build_service_spec.rb @@ -14,7 +14,7 @@ describe Ci::PrepareBuildService do shared_examples 'build enqueueing' do it 'enqueues the build' do - expect(build).to receive(:enqueue).once + expect(build).to receive(:enqueue_preparing).once subject end @@ -34,7 +34,7 @@ describe Ci::PrepareBuildService do context 'prerequisites fail to complete' do before do - allow(build).to receive(:enqueue).and_return(false) + allow(build).to receive(:enqueue_preparing).and_return(false) end it 'drops the build' do diff --git a/spec/services/ci/process_pipeline_service_spec.rb b/spec/services/ci/process_pipeline_service_spec.rb index ba5891c8694..509a4231472 100644 --- a/spec/services/ci/process_pipeline_service_spec.rb +++ b/spec/services/ci/process_pipeline_service_spec.rb @@ -261,12 +261,16 @@ describe Ci::ProcessPipelineService, '#execute' do expect(builds_names_and_statuses).to eq({ 'build': 'success', 'rollout10%': 'scheduled' }) - enqueue_scheduled('rollout10%') + Timecop.travel 2.minutes.from_now do + enqueue_scheduled('rollout10%') + end succeed_pending expect(builds_names_and_statuses).to eq({ 'build': 'success', 'rollout10%': 'success', 'rollout100%': 'scheduled' }) - enqueue_scheduled('rollout100%') + Timecop.travel 2.minutes.from_now do + enqueue_scheduled('rollout100%') + end succeed_pending expect(builds_names_and_statuses).to eq({ 'build': 'success', 'rollout10%': 'success', 'rollout100%': 'success', 'cleanup': 'pending' }) @@ -328,7 +332,9 @@ describe Ci::ProcessPipelineService, '#execute' do expect(builds_names_and_statuses).to eq({ 'build': 'success', 'rollout10%': 'scheduled' }) - enqueue_scheduled('rollout10%') + Timecop.travel 2.minutes.from_now do + enqueue_scheduled('rollout10%') + end fail_running_or_pending expect(builds_names_and_statuses).to eq({ 'build': 'success', 'rollout10%': 'failed' }) @@ -394,7 +400,9 @@ describe Ci::ProcessPipelineService, '#execute' do expect(process_pipeline).to be_truthy expect(builds_names_and_statuses).to eq({ 'delayed1': 'scheduled', 'delayed2': 'scheduled' }) - enqueue_scheduled('delayed1') + Timecop.travel 2.minutes.from_now do + enqueue_scheduled('delayed1') + end expect(builds_names_and_statuses).to eq({ 'delayed1': 'pending', 'delayed2': 'scheduled' }) expect(pipeline.reload.status).to eq 'running' @@ -413,7 +421,9 @@ describe Ci::ProcessPipelineService, '#execute' do expect(process_pipeline).to be_truthy expect(builds_names_and_statuses).to eq({ 'delayed': 'scheduled' }) - enqueue_scheduled('delayed') + Timecop.travel 2.minutes.from_now do + enqueue_scheduled('delayed') + end fail_running_or_pending expect(builds_names_and_statuses).to eq({ 'delayed': 'failed', 'job': 'pending' }) @@ -906,7 +916,7 @@ describe Ci::ProcessPipelineService, '#execute' do end def enqueue_scheduled(name) - builds.scheduled.find_by(name: name).enqueue + builds.scheduled.find_by(name: name).enqueue_scheduled end def retry_build(name) diff --git a/spec/services/ci/resource_groups/assign_resource_from_resource_group_service_spec.rb b/spec/services/ci/resource_groups/assign_resource_from_resource_group_service_spec.rb new file mode 100644 index 00000000000..50d312647ae --- /dev/null +++ b/spec/services/ci/resource_groups/assign_resource_from_resource_group_service_spec.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Ci::ResourceGroups::AssignResourceFromResourceGroupService do + let_it_be(:project) { create(:project) } + let_it_be(:user) { create(:user) } + let(:service) { described_class.new(project, user) } + + describe '#execute' do + subject { service.execute(resource_group) } + + let(:resource_group) { create(:ci_resource_group, project: project) } + let!(:build) { create(:ci_build, :waiting_for_resource, project: project, user: user, resource_group: resource_group) } + + context 'when there is an available resource' do + it 'requests resource' do + subject + + expect(build.reload).to be_pending + expect(build.resource).to be_present + end + + context 'when failed to request resource' do + before do + allow_next_instance_of(Ci::Build) do |build| + allow(build).to receive(:enqueue_waiting_for_resource) { false } + end + end + + it 'has a build waiting for resource' do + subject + + expect(build).to be_waiting_for_resource + end + end + + context 'when the build has already retained a resource' do + before do + resource_group.assign_resource_to(build) + build.update_column(:status, :pending) + end + + it 'has a pending build' do + subject + + expect(build).to be_pending + end + end + end + + context 'when there are no available resources' do + before do + resource_group.assign_resource_to(create(:ci_build)) + end + + it 'does not request resource' do + expect_any_instance_of(Ci::Build).not_to receive(:enqueue_waiting_for_resource) + + subject + end + end + end +end diff --git a/spec/services/ci/run_scheduled_build_service_spec.rb b/spec/services/ci/run_scheduled_build_service_spec.rb index ab8d9f4ba2e..43d110cbc8f 100644 --- a/spec/services/ci/run_scheduled_build_service_spec.rb +++ b/spec/services/ci/run_scheduled_build_service_spec.rb @@ -26,6 +26,18 @@ describe Ci::RunScheduledBuildService do expect(build).to be_pending end + + context 'when build requires resource' do + let(:resource_group) { create(:ci_resource_group, project: project) } + + before do + build.update!(resource_group: resource_group) + end + + it 'transits to waiting for resource status' do + expect { subject }.to change { build.status }.from('scheduled').to('waiting_for_resource') + end + end end context 'when scheduled_at is not expired' do diff --git a/spec/workers/ci/resource_groups/assign_resource_from_resource_group_worker_spec.rb b/spec/workers/ci/resource_groups/assign_resource_from_resource_group_worker_spec.rb new file mode 100644 index 00000000000..634d932121e --- /dev/null +++ b/spec/workers/ci/resource_groups/assign_resource_from_resource_group_worker_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Ci::ResourceGroups::AssignResourceFromResourceGroupWorker do + let(:worker) { described_class.new } + + describe '#perform' do + subject { worker.perform(resource_group_id) } + + context 'when resource group exists' do + let(:resource_group) { create(:ci_resource_group) } + let(:resource_group_id) { resource_group.id } + + it 'executes AssignResourceFromResourceGroupService' do + expect_next_instance_of(Ci::ResourceGroups::AssignResourceFromResourceGroupService, resource_group.project, nil) do |service| + expect(service).to receive(:execute).with(resource_group) + end + + subject + end + end + + context 'when build does not exist' do + let(:resource_group_id) { 123 } + + it 'does not execute AssignResourceFromResourceGroupService' do + expect(Ci::ResourceGroups::AssignResourceFromResourceGroupService).not_to receive(:new) + + subject + end + end + end +end diff --git a/spec/workers/git_garbage_collect_worker_spec.rb b/spec/workers/git_garbage_collect_worker_spec.rb index cc1c23bb9e7..64ad4ba7eb6 100644 --- a/spec/workers/git_garbage_collect_worker_spec.rb +++ b/spec/workers/git_garbage_collect_worker_spec.rb @@ -230,8 +230,8 @@ describe GitGarbageCollectWorker do new_commit_sha = Rugged::Commit.create( rugged, message: "hello world #{SecureRandom.hex(6)}", - author: Gitlab::Git.committer_hash(email: 'foo@bar', name: 'baz'), - committer: Gitlab::Git.committer_hash(email: 'foo@bar', name: 'baz'), + author: { email: 'foo@bar', name: 'baz' }, + committer: { email: 'foo@bar', name: 'baz' }, tree: old_commit.tree, parents: [old_commit] ) |