diff options
Diffstat (limited to 'spec/services/ci/retry_job_service_spec.rb')
-rw-r--r-- | spec/services/ci/retry_job_service_spec.rb | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/spec/services/ci/retry_job_service_spec.rb b/spec/services/ci/retry_job_service_spec.rb index c3d80f2cb56..10acf032b1a 100644 --- a/spec/services/ci/retry_job_service_spec.rb +++ b/spec/services/ci/retry_job_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::RetryJobService do +RSpec.describe Ci::RetryJobService, feature_category: :continuous_integration do using RSpec::Parameterized::TableSyntax let_it_be(:reporter) { create(:user) } let_it_be(:developer) { create(:user) } @@ -27,6 +27,22 @@ RSpec.describe Ci::RetryJobService do project.add_reporter(reporter) end + shared_context 'retryable bridge' do + let_it_be(:downstream_project) { create(:project, :repository) } + + let_it_be_with_refind(:job) do + create(:ci_bridge, :success, + pipeline: pipeline, downstream: downstream_project, description: 'a trigger job', ci_stage: stage + ) + end + + let_it_be(:job_to_clone) { job } + + before do + job.update!(retried: false) + end + end + shared_context 'retryable build' do let_it_be_with_reload(:job) do create(:ci_build, :success, pipeline: pipeline, ci_stage: stage) @@ -102,6 +118,14 @@ RSpec.describe Ci::RetryJobService do end end + shared_examples_for 'does not retry the job' do + it 'returns :not_retryable and :unprocessable_entity' do + expect(subject.message).to be('Job cannot be retried') + expect(subject.payload[:reason]).to eq(:not_retryable) + expect(subject.payload[:job]).to eq(job) + end + end + shared_examples_for 'retries the job' do it_behaves_like 'clones the job' @@ -189,6 +213,20 @@ RSpec.describe Ci::RetryJobService do expect { service.clone!(create(:ci_build).present) }.to raise_error(TypeError) end + context 'when the job to be cloned is a bridge' do + include_context 'retryable bridge' + + it_behaves_like 'clones the job' + + context 'when given variables' do + let(:new_job) { service.clone!(job, variables: job_variables_attributes) } + + it 'does not give variables to the new bridge' do + expect { new_job }.not_to raise_error + end + end + end + context 'when the job to be cloned is a build' do include_context 'retryable build' @@ -287,7 +325,33 @@ RSpec.describe Ci::RetryJobService do subject { service.execute(job) } + context 'when the job to be retried is a bridge' do + context 'and it is not retryable' do + let_it_be(:job) { create(:ci_bridge, :failed, :reached_max_descendant_pipelines_depth) } + + it_behaves_like 'does not retry the job' + end + + include_context 'retryable bridge' + + it_behaves_like 'retries the job' + + context 'when given variables' do + let(:new_job) { service.clone!(job, variables: job_variables_attributes) } + + it 'does not give variables to the new bridge' do + expect { new_job }.not_to raise_error + end + end + end + context 'when the job to be retried is a build' do + context 'and it is not retryable' do + let_it_be(:job) { create(:ci_build, :deployment_rejected, pipeline: pipeline) } + + it_behaves_like 'does not retry the job' + end + include_context 'retryable build' it_behaves_like 'retries the job' |