diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
commit | aee0a117a889461ce8ced6fcf73207fe017f1d99 (patch) | |
tree | 891d9ef189227a8445d83f35c1b0fc99573f4380 /spec/services/projects | |
parent | 8d46af3258650d305f53b819eabf7ab18d22f59e (diff) |
Add latest changes from gitlab-org/gitlab@14-6-stable-eev14.6.0-rc42
Diffstat (limited to 'spec/services/projects')
5 files changed, 43 insertions, 96 deletions
diff --git a/spec/services/projects/destroy_service_spec.rb b/spec/services/projects/destroy_service_spec.rb index ac84614121a..b22f276ee1f 100644 --- a/spec/services/projects/destroy_service_spec.rb +++ b/spec/services/projects/destroy_service_spec.rb @@ -55,48 +55,16 @@ RSpec.describe Projects::DestroyService, :aggregate_failures do .and change { Ci::Pipeline.count }.by(-1) end - context 'with abort_deleted_project_pipelines disabled' do - stub_feature_flags(abort_deleted_project_pipelines: false) + it 'avoids N+1 queries' do + recorder = ActiveRecord::QueryRecorder.new { destroy_project(project, user, {}) } - it 'avoids N+1 queries' do - recorder = ActiveRecord::QueryRecorder.new { destroy_project(project, user, {}) } + project = create(:project, :repository, namespace: user.namespace) + pipeline = create(:ci_pipeline, project: project) + builds = create_list(:ci_build, 3, :artifacts, pipeline: pipeline) + create(:ci_pipeline_artifact, pipeline: pipeline) + create_list(:ci_build_trace_chunk, 3, build: builds[0]) - project = create(:project, :repository, namespace: user.namespace) - pipeline = create(:ci_pipeline, project: project) - builds = create_list(:ci_build, 3, :artifacts, pipeline: pipeline) - create(:ci_pipeline_artifact, pipeline: pipeline) - create_list(:ci_build_trace_chunk, 3, build: builds[0]) - - expect { destroy_project(project, project.owner, {}) }.not_to exceed_query_limit(recorder) - end - end - - context 'with ci_optimize_project_records_destruction disabled' do - stub_feature_flags(ci_optimize_project_records_destruction: false) - - it 'avoids N+1 queries' do - recorder = ActiveRecord::QueryRecorder.new { destroy_project(project, user, {}) } - - project = create(:project, :repository, namespace: user.namespace) - pipeline = create(:ci_pipeline, project: project) - builds = create_list(:ci_build, 3, :artifacts, pipeline: pipeline) - create_list(:ci_build_trace_chunk, 3, build: builds[0]) - - expect { destroy_project(project, project.owner, {}) }.not_to exceed_query_limit(recorder) - end - end - - context 'with ci_optimize_project_records_destruction and abort_deleted_project_pipelines enabled' do - it 'avoids N+1 queries' do - recorder = ActiveRecord::QueryRecorder.new { destroy_project(project, user, {}) } - - project = create(:project, :repository, namespace: user.namespace) - pipeline = create(:ci_pipeline, project: project) - builds = create_list(:ci_build, 3, :artifacts, pipeline: pipeline) - create_list(:ci_build_trace_chunk, 3, build: builds[0]) - - expect { destroy_project(project, project.owner, {}) }.not_to exceed_query_limit(recorder) - end + expect { destroy_project(project, project.owner, {}) }.not_to exceed_query_limit(recorder) end it_behaves_like 'deleting the project' @@ -132,64 +100,22 @@ RSpec.describe Projects::DestroyService, :aggregate_failures do destroy_project(project, user, {}) end - context 'with abort_deleted_project_pipelines feature disabled' do - before do - stub_feature_flags(abort_deleted_project_pipelines: false) - end - - it 'does not bulk-fail project ci pipelines' do - expect(::Ci::AbortPipelinesService).not_to receive(:new) - - destroy_project(project, user, {}) - end - - it 'does not destroy CI records via DestroyPipelineService' do - expect(::Ci::DestroyPipelineService).not_to receive(:new) - - destroy_project(project, user, {}) - end - end - - context 'with abort_deleted_project_pipelines feature enabled' do + context 'with running pipelines' do let!(:pipelines) { create_list(:ci_pipeline, 3, :running, project: project) } let(:destroy_pipeline_service) { double('DestroyPipelineService', execute: nil) } - context 'with ci_optimize_project_records_destruction disabled' do - before do - stub_feature_flags(ci_optimize_project_records_destruction: false) - end - - it 'bulk-fails project ci pipelines' do - expect(::Ci::AbortPipelinesService) - .to receive_message_chain(:new, :execute) - .with(project.all_pipelines, :project_deleted) - - destroy_project(project, user, {}) - end + it 'bulks-fails with AbortPipelineService and then executes DestroyPipelineService for each pipelines' do + allow(::Ci::DestroyPipelineService).to receive(:new).and_return(destroy_pipeline_service) - it 'does not destroy CI records via DestroyPipelineService' do - expect(::Ci::DestroyPipelineService).not_to receive(:new) + expect(::Ci::AbortPipelinesService) + .to receive_message_chain(:new, :execute) + .with(project.all_pipelines, :project_deleted) - destroy_project(project, user, {}) + pipelines.each do |pipeline| + expect(destroy_pipeline_service).to receive(:execute).with(pipeline) end - end - - context 'with ci_optimize_project_records_destruction enabled' do - it 'executes DestroyPipelineService for project ci pipelines' do - allow(::Ci::DestroyPipelineService).to receive(:new).and_return(destroy_pipeline_service) - expect(::Ci::AbortPipelinesService) - .to receive_message_chain(:new, :execute) - .with(project.all_pipelines, :project_deleted) - - pipelines.each do |pipeline| - expect(destroy_pipeline_service) - .to receive(:execute) - .with(pipeline) - end - - destroy_project(project, user, {}) - end + destroy_project(project, user, {}) end end @@ -545,6 +471,27 @@ RSpec.describe Projects::DestroyService, :aggregate_failures do end end + context 'when project has events' do + let!(:event) { create(:event, :created, project: project, target: project, author: user) } + + it 'deletes events from the project' do + expect do + destroy_project(project, user) + end.to change(Event, :count).by(-1) + end + + context 'when an error is returned while deleting events' do + it 'does not delete project' do + allow_next_instance_of(Events::DestroyService) do |instance| + allow(instance).to receive(:execute).and_return(ServiceResponse.error(message: 'foo')) + end + + expect(destroy_project(project, user)).to be_falsey + expect(project.delete_error).to include('Failed to remove events') + end + end + end + context 'error while destroying', :sidekiq_inline do let!(:pipeline) { create(:ci_pipeline, project: project) } let!(:builds) { create_list(:ci_build, 2, :artifacts, pipeline: pipeline) } diff --git a/spec/services/projects/prometheus/alerts/create_service_spec.rb b/spec/services/projects/prometheus/alerts/create_service_spec.rb index c0bc9336558..6b9d43e4e81 100644 --- a/spec/services/projects/prometheus/alerts/create_service_spec.rb +++ b/spec/services/projects/prometheus/alerts/create_service_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Projects::Prometheus::Alerts::CreateService do let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } - let(:service) { described_class.new(project, user, params) } + let(:service) { described_class.new(project: project, current_user: user, params: params) } subject { service.execute } diff --git a/spec/services/projects/prometheus/alerts/destroy_service_spec.rb b/spec/services/projects/prometheus/alerts/destroy_service_spec.rb index 573711051b7..a3e9c3516c2 100644 --- a/spec/services/projects/prometheus/alerts/destroy_service_spec.rb +++ b/spec/services/projects/prometheus/alerts/destroy_service_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Projects::Prometheus::Alerts::DestroyService do let_it_be(:user) { create(:user) } let_it_be(:alert) { create(:prometheus_alert, project: project) } - let(:service) { described_class.new(project, user, nil) } + let(:service) { described_class.new(project: project, current_user: user, params: nil) } describe '#execute' do subject { service.execute(alert) } diff --git a/spec/services/projects/prometheus/alerts/update_service_spec.rb b/spec/services/projects/prometheus/alerts/update_service_spec.rb index e831d001838..ec6766221f6 100644 --- a/spec/services/projects/prometheus/alerts/update_service_spec.rb +++ b/spec/services/projects/prometheus/alerts/update_service_spec.rb @@ -11,7 +11,7 @@ RSpec.describe Projects::Prometheus::Alerts::UpdateService do create(:prometheus_alert, project: project, environment: environment) end - let(:service) { described_class.new(project, user, params) } + let(:service) { described_class.new(project: project, current_user: user, params: params) } let(:params) do { diff --git a/spec/services/projects/transfer_service_spec.rb b/spec/services/projects/transfer_service_spec.rb index c47d44002cc..ddd16100b40 100644 --- a/spec/services/projects/transfer_service_spec.rb +++ b/spec/services/projects/transfer_service_spec.rb @@ -169,7 +169,7 @@ RSpec.describe Projects::TransferService do end end - context 'when project has pending builds' do + context 'when project has pending builds', :sidekiq_inline do let!(:other_project) { create(:project) } let!(:pending_build) { create(:ci_pending_build, project: project.reload) } let!(:unrelated_pending_build) { create(:ci_pending_build, project: other_project) } @@ -251,7 +251,7 @@ RSpec.describe Projects::TransferService do ) end - context 'when project has pending builds' do + context 'when project has pending builds', :sidekiq_inline do let!(:other_project) { create(:project) } let!(:pending_build) { create(:ci_pending_build, project: project.reload) } let!(:unrelated_pending_build) { create(:ci_pending_build, project: other_project) } |