Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/workers/ci')
-rw-r--r--spec/workers/ci/create_cross_project_pipeline_worker_spec.rb1
-rw-r--r--spec/workers/ci/delete_unit_tests_worker_spec.rb33
-rw-r--r--spec/workers/ci/merge_requests/add_todo_when_build_fails_worker_spec.rb2
-rw-r--r--spec/workers/ci/pipeline_artifacts/create_quality_report_worker_spec.rb4
-rw-r--r--spec/workers/ci/pipeline_artifacts/expire_artifacts_worker_spec.rb2
-rw-r--r--spec/workers/ci/retry_pipeline_worker_spec.rb51
6 files changed, 89 insertions, 4 deletions
diff --git a/spec/workers/ci/create_cross_project_pipeline_worker_spec.rb b/spec/workers/ci/create_cross_project_pipeline_worker_spec.rb
index 116e6878281..372b0de1b54 100644
--- a/spec/workers/ci/create_cross_project_pipeline_worker_spec.rb
+++ b/spec/workers/ci/create_cross_project_pipeline_worker_spec.rb
@@ -6,6 +6,7 @@ RSpec.describe Ci::CreateCrossProjectPipelineWorker do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
+
let(:bridge) { create(:ci_bridge, user: user, pipeline: pipeline) }
let(:service) { double('pipeline creation service') }
diff --git a/spec/workers/ci/delete_unit_tests_worker_spec.rb b/spec/workers/ci/delete_unit_tests_worker_spec.rb
new file mode 100644
index 00000000000..ff2575b19c1
--- /dev/null
+++ b/spec/workers/ci/delete_unit_tests_worker_spec.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Ci::DeleteUnitTestsWorker do
+ let(:worker) { described_class.new }
+
+ describe '#perform' do
+ it 'executes a service' do
+ expect_next_instance_of(Ci::DeleteUnitTestsService) do |instance|
+ expect(instance).to receive(:execute)
+ end
+
+ worker.perform
+ end
+ end
+
+ it_behaves_like 'an idempotent worker' do
+ let!(:unit_test_1) { create(:ci_unit_test) }
+ let!(:unit_test_2) { create(:ci_unit_test) }
+ let!(:unit_test_1_recent_failure) { create(:ci_unit_test_failure, unit_test: unit_test_1) }
+ let!(:unit_test_2_old_failure) { create(:ci_unit_test_failure, unit_test: unit_test_2, failed_at: 15.days.ago) }
+
+ it 'only deletes old unit tests and their failures' do
+ subject
+
+ expect(unit_test_1.reload).to be_persisted
+ expect(unit_test_1_recent_failure.reload).to be_persisted
+ expect(Ci::UnitTest.find_by(id: unit_test_2.id)).to be_nil
+ expect(Ci::UnitTestFailure.find_by(id: unit_test_2_old_failure.id)).to be_nil
+ end
+ end
+end
diff --git a/spec/workers/ci/merge_requests/add_todo_when_build_fails_worker_spec.rb b/spec/workers/ci/merge_requests/add_todo_when_build_fails_worker_spec.rb
index 4690c73d121..e5de0ba0143 100644
--- a/spec/workers/ci/merge_requests/add_todo_when_build_fails_worker_spec.rb
+++ b/spec/workers/ci/merge_requests/add_todo_when_build_fails_worker_spec.rb
@@ -15,7 +15,7 @@ RSpec.describe Ci::MergeRequests::AddTodoWhenBuildFailsWorker do
include_examples 'an idempotent worker' do
it 'executes todo service' do
service = double
- expect(::MergeRequests::AddTodoWhenBuildFailsService).to receive(:new).with(project, nil).and_return(service).twice
+ expect(::MergeRequests::AddTodoWhenBuildFailsService).to receive(:new).with(project: project).and_return(service).twice
expect(service).to receive(:execute).with(job).twice
perform_twice
diff --git a/spec/workers/ci/pipeline_artifacts/create_quality_report_worker_spec.rb b/spec/workers/ci/pipeline_artifacts/create_quality_report_worker_spec.rb
index be351032b58..5096691270a 100644
--- a/spec/workers/ci/pipeline_artifacts/create_quality_report_worker_spec.rb
+++ b/spec/workers/ci/pipeline_artifacts/create_quality_report_worker_spec.rb
@@ -21,8 +21,8 @@ RSpec.describe ::Ci::PipelineArtifacts::CreateQualityReportWorker do
it_behaves_like 'an idempotent worker' do
let(:job_args) { pipeline_id }
- it 'creates a pipeline artifact' do
- expect { subject }.to change { pipeline.pipeline_artifacts.count }.by(1)
+ it 'does not create another pipeline artifact if already has one' do
+ expect { subject }.not_to change { pipeline.pipeline_artifacts.count }
end
end
end
diff --git a/spec/workers/ci/pipeline_artifacts/expire_artifacts_worker_spec.rb b/spec/workers/ci/pipeline_artifacts/expire_artifacts_worker_spec.rb
index ad9c08d02cb..274f848ad88 100644
--- a/spec/workers/ci/pipeline_artifacts/expire_artifacts_worker_spec.rb
+++ b/spec/workers/ci/pipeline_artifacts/expire_artifacts_worker_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe Ci::PipelineArtifacts::ExpireArtifactsWorker do
describe '#perform' do
let_it_be(:pipeline_artifact) do
- create(:ci_pipeline_artifact, :with_coverage_report, expire_at: 1.week.ago)
+ create(:ci_pipeline_artifact, :with_coverage_report, :unlocked, expire_at: 1.week.ago)
end
it 'executes a service' do
diff --git a/spec/workers/ci/retry_pipeline_worker_spec.rb b/spec/workers/ci/retry_pipeline_worker_spec.rb
new file mode 100644
index 00000000000..c7600a24280
--- /dev/null
+++ b/spec/workers/ci/retry_pipeline_worker_spec.rb
@@ -0,0 +1,51 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Ci::RetryPipelineWorker do
+ describe '#perform' do
+ subject(:perform) { described_class.new.perform(pipeline_id, user_id) }
+
+ let(:pipeline) { create(:ci_pipeline) }
+
+ context 'when pipeline exists' do
+ let(:pipeline_id) { pipeline.id }
+
+ context 'when user exists' do
+ let(:user) { create(:user) }
+ let(:user_id) { user.id }
+
+ before do
+ pipeline.project.add_maintainer(user)
+ end
+
+ it 'retries the pipeline' do
+ expect(::Ci::Pipeline).to receive(:find_by_id).with(pipeline.id).and_return(pipeline)
+ expect(pipeline).to receive(:retry_failed).with(having_attributes(id: user_id))
+
+ perform
+ end
+ end
+
+ context 'when user does not exist' do
+ let(:user_id) { 1234 }
+
+ it 'does not retry the pipeline' do
+ expect(::Ci::Pipeline).to receive(:find_by_id).with(pipeline_id).and_return(pipeline)
+ expect(pipeline).not_to receive(:retry_failed).with(having_attributes(id: user_id))
+
+ perform
+ end
+ end
+ end
+
+ context 'when pipeline does not exist' do
+ let(:pipeline_id) { 1234 }
+ let(:user_id) { 1234 }
+
+ it 'returns nil' do
+ expect(perform).to be_nil
+ end
+ end
+ end
+end