From 8a71d40e60c799f969af0ed255e931b6c9907634 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 31 Mar 2017 16:59:46 -0700 Subject: Fix race condition where a namespace would be deleted before a project was deleted When deleting a user, the following sequence could happen: 1. Project `mygroup/myproject` is scheduled for deletion 2. The group `mygroup` is deleted 3. Sidekiq worker runs to delete `mygroup/myproject`, but the namespace and routes have been destroyed. Closes #30334 --- spec/services/users/destroy_spec.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'spec/services') diff --git a/spec/services/users/destroy_spec.rb b/spec/services/users/destroy_spec.rb index 9a28c03d968..66c61b7f8ff 100644 --- a/spec/services/users/destroy_spec.rb +++ b/spec/services/users/destroy_spec.rb @@ -17,13 +17,28 @@ describe Users::DestroyService, services: true do expect { Namespace.with_deleted.find(user.namespace.id) }.to raise_error(ActiveRecord::RecordNotFound) end - it 'will delete the project in the near future' do - expect_any_instance_of(Projects::DestroyService).to receive(:async_execute).once + it 'will delete the project' do + expect_any_instance_of(Projects::DestroyService).to receive(:execute).once service.execute(user) end end + context 'projects in pending_delete' do + before do + project.pending_delete = true + project.save + end + + it 'destroys a project in pending_delete' do + expect_any_instance_of(Projects::DestroyService).to receive(:execute).once + + service.execute(user) + + expect { Project.find(project.id) }.to raise_error(ActiveRecord::RecordNotFound) + end + end + context "a deleted user's issues" do let(:project) { create(:project) } -- cgit v1.2.3