summaryrefslogtreecommitdiff
path: root/spec/services/projects/destroy_service_spec.rb
diff options
context:
space:
mode:
authorTimothy Andrew <mail@timothyandrew.net>2017-04-28 06:46:15 +0000
committerTiago Botelho <tiagonbotelho@hotmail.com>2017-07-20 09:56:52 +0100
commit72a85ae9ac2468b099a565d3848bf8e0dcdf4499 (patch)
tree9d95fe450c896cb4b80b19fd247eb5660fde2a2b /spec/services/projects/destroy_service_spec.rb
parent445cd22c72ca6fbfdcf18d67fa859c4b5b9e2a6c (diff)
downloadgitlab-ce-72a85ae9ac2468b099a565d3848bf8e0dcdf4499.tar.gz
Handle errors while a project is being deleted asynchronously.
1. Rescue all errors that `Projects::DestroyService` might throw, to prevent the worker from leaving things in an inconsistent state 2. Unmark the project as `pending_delete` 3. Add a `delete_error` text column to `projects`, and save the error message in there, to be shown to the project masters/owners.
Diffstat (limited to 'spec/services/projects/destroy_service_spec.rb')
-rw-r--r--spec/services/projects/destroy_service_spec.rb63
1 files changed, 63 insertions, 0 deletions
diff --git a/spec/services/projects/destroy_service_spec.rb b/spec/services/projects/destroy_service_spec.rb
index b399d3402fd..a629afe723d 100644
--- a/spec/services/projects/destroy_service_spec.rb
+++ b/spec/services/projects/destroy_service_spec.rb
@@ -36,6 +36,27 @@ describe Projects::DestroyService, services: true do
end
end
+ shared_examples 'handles errors thrown during async destroy' do |error_message|
+ it 'does not allow the error to bubble up' do
+ expect do
+ Sidekiq::Testing.inline! { destroy_project(project, user, {}) }
+ end.not_to raise_error
+ end
+
+ it 'unmarks the project as "pending deletion"' do
+ Sidekiq::Testing.inline! { destroy_project(project, user, {}) }
+
+ expect(project.reload.pending_delete).to be(false)
+ end
+
+ it 'stores an error message in `projects.delete_error`' do
+ Sidekiq::Testing.inline! { destroy_project(project, user, {}) }
+
+ expect(project.reload.delete_error).to be_present
+ expect(project.delete_error).to include(error_message)
+ end
+ end
+
context 'Sidekiq inline' do
before do
# Run sidekiq immediatly to check that renamed repository will be removed
@@ -89,10 +110,52 @@ describe Projects::DestroyService, services: true do
end
it_behaves_like 'deleting the project with pipeline and build'
+
+ context 'errors' do
+ context 'when `remove_legacy_registry_tags` fails' do
+ before do
+ expect_any_instance_of(Projects::DestroyService)
+ .to receive(:remove_legacy_registry_tags).and_return(false)
+ end
+
+ it_behaves_like 'handles errors thrown during async destroy', "Failed to remove some tags"
+ end
+
+ context 'when `remove_repository` fails' do
+ before do
+ expect_any_instance_of(Projects::DestroyService)
+ .to receive(:remove_repository).and_return(false)
+ end
+
+ it_behaves_like 'handles errors thrown during async destroy', "Failed to remove project repository"
+ end
+
+ context 'when `execute` raises any other error' do
+ before do
+ expect_any_instance_of(Projects::DestroyService)
+ .to receive(:execute).and_raise(ArgumentError.new("Other error message"))
+ end
+
+ it_behaves_like 'handles errors thrown during async destroy', "Other error message"
+ end
+ end
end
context 'with execute' do
it_behaves_like 'deleting the project with pipeline and build'
+
+ context 'when `execute` raises an error' do
+ before do
+ expect_any_instance_of(Projects::DestroyService)
+ .to receive(:execute).and_raise(ArgumentError)
+ end
+
+ it 'allows the error to bubble up' do
+ expect do
+ Sidekiq::Testing.inline! { Projects::DestroyService.new(project, user, {}).execute }
+ end.to raise_error(ArgumentError)
+ end
+ end
end
describe 'container registry' do