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/merge_requests/delete_source_branch_worker_spec.rb')
-rw-r--r--spec/workers/merge_requests/delete_source_branch_worker_spec.rb120
1 files changed, 70 insertions, 50 deletions
diff --git a/spec/workers/merge_requests/delete_source_branch_worker_spec.rb b/spec/workers/merge_requests/delete_source_branch_worker_spec.rb
index fe677103fd0..2935d3ef5dc 100644
--- a/spec/workers/merge_requests/delete_source_branch_worker_spec.rb
+++ b/spec/workers/merge_requests/delete_source_branch_worker_spec.rb
@@ -10,96 +10,116 @@ RSpec.describe MergeRequests::DeleteSourceBranchWorker do
let(:worker) { described_class.new }
describe '#perform' do
- context 'with a non-existing merge request' do
- it 'does nothing' do
- expect(::Branches::DeleteService).not_to receive(:new)
- expect(::MergeRequests::RetargetChainService).not_to receive(:new)
+ context 'when the add_delete_branch_worker feature flag is enabled' do
+ context 'with a non-existing merge request' do
+ it 'does nothing' do
+ expect(::MergeRequests::DeleteBranchWorker).not_to receive(:perform_async)
- worker.perform(non_existing_record_id, sha, user.id)
+ worker.perform(non_existing_record_id, sha, user.id)
+ end
end
- end
- context 'with a non-existing user' do
- it 'does nothing' do
- expect(::Branches::DeleteService).not_to receive(:new)
- expect(::MergeRequests::RetargetChainService).not_to receive(:new)
+ context 'with a non-existing user' do
+ it 'does nothing' do
+ expect(::MergeRequests::DeleteBranchWorker).not_to receive(:perform_async)
- worker.perform(merge_request.id, sha, non_existing_record_id)
+ worker.perform(merge_request.id, sha, non_existing_record_id)
+ end
end
- end
- context 'with existing user and merge request' do
- it 'calls service to delete source branch' do
- expect_next_instance_of(::Branches::DeleteService) do |instance|
- expect(instance).to receive(:execute).with(merge_request.source_branch)
+ context 'with existing user and merge request' do
+ it 'creates a new delete branch worker async' do
+ expect(::MergeRequests::DeleteBranchWorker).to receive(:perform_async).with(merge_request.id, user.id,
+ merge_request.source_branch, true)
+
+ worker.perform(merge_request.id, sha, user.id)
end
- worker.perform(merge_request.id, sha, user.id)
- end
+ context 'source branch sha does not match' do
+ it 'does nothing' do
+ expect(::MergeRequests::DeleteBranchWorker).not_to receive(:perform_async)
- it 'calls service to try retarget merge requests' do
- expect_next_instance_of(::MergeRequests::RetargetChainService) do |instance|
- expect(instance).to receive(:execute).with(merge_request)
+ worker.perform(merge_request.id, 'new-source-branch-sha', user.id)
+ end
end
+ end
- worker.perform(merge_request.id, sha, user.id)
+ it_behaves_like 'an idempotent worker' do
+ let(:merge_request) { create(:merge_request) }
+ let(:job_args) { [merge_request.id, sha, user.id] }
+ end
+ end
+
+ context 'when the add_delete_branch_worker feature flag is disabled' do
+ before do
+ stub_feature_flags(add_delete_branch_worker: false)
end
- context 'source branch sha does not match' do
+ context 'with a non-existing merge request' do
it 'does nothing' do
expect(::Branches::DeleteService).not_to receive(:new)
expect(::MergeRequests::RetargetChainService).not_to receive(:new)
- worker.perform(merge_request.id, 'new-source-branch-sha', user.id)
+ worker.perform(non_existing_record_id, sha, user.id)
end
end
- context 'when delete service returns an error' do
- let(:service_result) { ServiceResponse.error(message: 'placeholder') }
+ context 'with a non-existing user' do
+ it 'does nothing' do
+ expect(::Branches::DeleteService).not_to receive(:new)
+ expect(::MergeRequests::RetargetChainService).not_to receive(:new)
+
+ worker.perform(merge_request.id, sha, non_existing_record_id)
+ end
+ end
- it 'tracks the exception' do
+ context 'with existing user and merge request' do
+ it 'calls service to delete source branch' do
expect_next_instance_of(::Branches::DeleteService) do |instance|
- expect(instance).to receive(:execute).with(merge_request.source_branch).and_return(service_result)
+ expect(instance).to receive(:execute).with(merge_request.source_branch)
end
- expect(service_result).to receive(:track_exception).and_call_original
+ worker.perform(merge_request.id, sha, user.id)
+ end
+
+ it 'calls service to try retarget merge requests' do
+ expect_next_instance_of(::MergeRequests::RetargetChainService) do |instance|
+ expect(instance).to receive(:execute).with(merge_request)
+ end
worker.perform(merge_request.id, sha, user.id)
end
- context 'when track_delete_source_errors is disabled' do
- before do
- stub_feature_flags(track_delete_source_errors: false)
+ context 'source branch sha does not match' do
+ it 'does nothing' do
+ expect(::Branches::DeleteService).not_to receive(:new)
+ expect(::MergeRequests::RetargetChainService).not_to receive(:new)
+
+ worker.perform(merge_request.id, 'new-source-branch-sha', user.id)
end
+ end
+
+ context 'when delete service returns an error' do
+ let(:service_result) { ServiceResponse.error(message: 'placeholder') }
- it 'does not track the exception' do
+ it 'still retargets the merge request' do
expect_next_instance_of(::Branches::DeleteService) do |instance|
expect(instance).to receive(:execute).with(merge_request.source_branch).and_return(service_result)
end
- expect(service_result).not_to receive(:track_exception)
+ expect_next_instance_of(::MergeRequests::RetargetChainService) do |instance|
+ expect(instance).to receive(:execute).with(merge_request)
+ end
worker.perform(merge_request.id, sha, user.id)
end
end
-
- it 'still retargets the merge request' do
- expect_next_instance_of(::Branches::DeleteService) do |instance|
- expect(instance).to receive(:execute).with(merge_request.source_branch).and_return(service_result)
- end
-
- expect_next_instance_of(::MergeRequests::RetargetChainService) do |instance|
- expect(instance).to receive(:execute).with(merge_request)
- end
-
- worker.perform(merge_request.id, sha, user.id)
- end
end
- end
- it_behaves_like 'an idempotent worker' do
- let(:merge_request) { create(:merge_request) }
- let(:job_args) { [merge_request.id, sha, user.id] }
+ it_behaves_like 'an idempotent worker' do
+ let(:merge_request) { create(:merge_request) }
+ let(:job_args) { [merge_request.id, sha, user.id] }
+ end
end
end
end