summaryrefslogtreecommitdiff
path: root/spec/services/projects/destroy_service_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/projects/destroy_service_spec.rb')
-rw-r--r--spec/services/projects/destroy_service_spec.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/services/projects/destroy_service_spec.rb b/spec/services/projects/destroy_service_spec.rb
index 7dcd03496bb..bc795b41839 100644
--- a/spec/services/projects/destroy_service_spec.rb
+++ b/spec/services/projects/destroy_service_spec.rb
@@ -1,6 +1,7 @@
require 'spec_helper'
describe Projects::DestroyService, services: true do
+ include DatabaseConnectionHelpers
let!(:user) { create(:user) }
let!(:project) { create(:project, namespace: user.namespace) }
let!(:path) { project.repository.path_to_repo }
@@ -45,6 +46,44 @@ describe Projects::DestroyService, services: true do
end
end
+ context 'potential race conditions' do
+ context "when the `ProjectDestroyWorker` task runs immediately" do
+ it "deletes the project" do
+ # Commit the contents of this spec's transaction so far
+ # so subsequent db connections can see it.
+ #
+ # DO NOT REMOVE THIS LINE, even if you see a WARNING with "No
+ # transaction is currently in progress". Without this, this
+ # spec will always be green, since the project created in setup
+ # cannot be seen by any other connections / threads in this spec.
+ Project.connection.commit_db_transaction
+
+ project_record = run_with_new_database_connection do |conn|
+ conn.execute("SELECT * FROM projects WHERE id = #{project.id}").first
+ end
+
+ expect(project_record).not_to be_nil
+
+ # Execute the contents of `ProjectDestroyWorker` in a separate thread, to
+ # simulate data manipulation by the Sidekiq worker (different database
+ # connection / transaction).
+ expect(ProjectDestroyWorker).to receive(:perform_async).and_wrap_original do |m, project_id, user_id, params|
+ Thread.new { m[project_id, user_id, params] }.join(5)
+ end
+
+ # Kick off the initial project destroy in a new thread, so that
+ # it doesn't share this spec's database transaction.
+ Thread.new { described_class.new(project, user).async_execute }.join(5)
+
+ project_record = run_with_new_database_connection do |conn|
+ conn.execute("SELECT * FROM projects WHERE id = #{project.id}").first
+ end
+
+ expect(project_record).to be_nil
+ end
+ end
+ end
+
context 'container registry' do
before do
stub_container_registry_config(enabled: true)