Commit 954827d7 authored by Marius Bobin's avatar Marius Bobin

Extract shared examples out of specs

Extract shared examples out of specs
parent 5c48b88c
...@@ -22,18 +22,30 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do ...@@ -22,18 +22,30 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do
describe '#execute' do describe '#execute' do
subject(:execute) { described_class.new(pipeline).execute } subject(:execute) { described_class.new(pipeline).execute }
shared_examples 'available CI quota' do
it 'does not drop the jobs' do
expect { execute }.not_to change { job.reload.status }
end
end
shared_examples 'limit exceeded' do
it 'drops the job' do
execute
job.reload
expect(job).to be_failed
expect(job.failure_reason).to eq('ci_quota_exceeded')
end
end
context 'with public projects' do context 'with public projects' do
before do before do
pipeline.project.update!(visibility_level: ::Gitlab::VisibilityLevel::PUBLIC) pipeline.project.update!(visibility_level: ::Gitlab::VisibilityLevel::PUBLIC)
end end
context 'with available CI quota' do it_behaves_like 'available CI quota'
it 'does not drop the jobs' do
expect { execute }.not_to change { job.reload.status }
end
end
context 'when the Ci quota is exceeded' do context 'when the CI quota is exceeded' do
before do before do
allow(pipeline.project).to receive(:ci_minutes_quota) allow(pipeline.project).to receive(:ci_minutes_quota)
.and_return(double('quota', minutes_used_up?: true)) .and_return(double('quota', minutes_used_up?: true))
...@@ -50,11 +62,7 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do ...@@ -50,11 +62,7 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do
pipeline.project.update!(visibility_level: ::Gitlab::VisibilityLevel::INTERNAL) pipeline.project.update!(visibility_level: ::Gitlab::VisibilityLevel::INTERNAL)
end end
context 'with available CI quota' do it_behaves_like 'available CI quota'
it 'does not drop the jobs' do
expect { execute }.not_to change { job.reload.status }
end
end
context 'when the Ci quota is exceeded' do context 'when the Ci quota is exceeded' do
before do before do
...@@ -62,13 +70,7 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do ...@@ -62,13 +70,7 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do
.and_return(double('quota', minutes_used_up?: true)) .and_return(double('quota', minutes_used_up?: true))
end end
it 'drops the job' do it_behaves_like 'limit exceeded'
execute
job.reload
expect(job).to be_failed
expect(job.failure_reason).to eq('ci_quota_exceeded')
end
end end
end end
...@@ -77,11 +79,7 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do ...@@ -77,11 +79,7 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do
pipeline.project.update!(visibility_level: ::Gitlab::VisibilityLevel::PRIVATE) pipeline.project.update!(visibility_level: ::Gitlab::VisibilityLevel::PRIVATE)
end end
context 'with available CI quota' do it_behaves_like 'available CI quota'
it 'does not drop the jobs' do
expect { execute }.not_to change { job.reload.status }
end
end
context 'when the Ci quota is exceeded' do context 'when the Ci quota is exceeded' do
before do before do
...@@ -89,13 +87,7 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do ...@@ -89,13 +87,7 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do
.and_return(double('quota', minutes_used_up?: true)) .and_return(double('quota', minutes_used_up?: true))
end end
it 'drops the job' do it_behaves_like 'limit exceeded'
execute
job.reload
expect(job).to be_failed
expect(job.failure_reason).to eq('ci_quota_exceeded')
end
end end
end end
end end
......
...@@ -54,7 +54,7 @@ RSpec.describe Ci::ProcessPipelineService, '#execute' do ...@@ -54,7 +54,7 @@ RSpec.describe Ci::ProcessPipelineService, '#execute' do
end end
context 'with no runners' do context 'with no runners' do
it 'creates a downstream cross-project pipeline' do it 'creates a failed downstream cross-project pipeline' do
service.execute service.execute
Sidekiq::Worker.drain_all Sidekiq::Worker.drain_all
......
...@@ -226,7 +226,7 @@ RSpec.describe Ci::CreatePipelineService do ...@@ -226,7 +226,7 @@ RSpec.describe Ci::CreatePipelineService do
end end
context 'when there are no runners matching the builds' do context 'when there are no runners matching the builds' do
it 'creates a pipeline with build_a and test_b pending; deploy_b manual', :sidekiq_inline do it 'creates a pipeline but all jobs failed', :sidekiq_inline do
processables = pipeline.processables processables = pipeline.processables
expect(pipeline).to be_created_successfully expect(pipeline).to be_created_successfully
......
...@@ -17,24 +17,26 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do ...@@ -17,24 +17,26 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do
describe '#execute' do describe '#execute' do
subject(:execute) { described_class.new(pipeline).execute } subject(:execute) { described_class.new(pipeline).execute }
shared_examples 'jobs allowed to run' do
it 'does not drop the jobs' do
expect { execute }.not_to change { job.reload.status }
end
end
context 'when the feature flag is disabled' do context 'when the feature flag is disabled' do
before do before do
stub_feature_flags(ci_drop_new_builds_when_ci_quota_exceeded: false) stub_feature_flags(ci_drop_new_builds_when_ci_quota_exceeded: false)
end end
it 'does not drop the jobs' do it_behaves_like 'jobs allowed to run'
expect { execute }.not_to change { job.reload.status }
end
end end
context 'when the pipeline status is not created' do context 'when the pipeline status is running' do
before do before do
pipeline.update!(status: :running) pipeline.update!(status: :running)
end end
it 'does not drop the jobs' do it_behaves_like 'jobs allowed to run'
expect { execute }.not_to change { job.reload.status }
end
end end
context 'when there are no runners available' do context 'when there are no runners available' do
...@@ -56,9 +58,7 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do ...@@ -56,9 +58,7 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do
create(:ci_runner, :online, runner_type: :project_type, projects: [project]) create(:ci_runner, :online, runner_type: :project_type, projects: [project])
end end
it 'does not drop the jobs' do it_behaves_like 'jobs allowed to run'
expect { execute }.not_to change { job.reload.status }
end
end end
context 'with group runners' do context 'with group runners' do
...@@ -66,9 +66,7 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do ...@@ -66,9 +66,7 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do
create(:ci_runner, :online, runner_type: :group_type, groups: [group]) create(:ci_runner, :online, runner_type: :group_type, groups: [group])
end end
it 'does not drop the jobs' do it_behaves_like 'jobs allowed to run'
expect { execute }.not_to change { job.reload.status }
end
end end
context 'with instance runners' do context 'with instance runners' do
...@@ -76,9 +74,7 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do ...@@ -76,9 +74,7 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do
create(:ci_runner, :online, runner_type: :instance_type) create(:ci_runner, :online, runner_type: :instance_type)
end end
it 'does not drop the jobs' do it_behaves_like 'jobs allowed to run'
expect { execute }.not_to change { job.reload.status }
end
end end
end end
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