From 98b3c82ac57951d5b42341a2c17b574fbf9dac65 Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 20 Sep 2021 02:09:14 -0500 Subject: [PATCH] tests: fix deadlock during artist ban test. The artist ban tests deadlocked because of a weird interaction between threads and database transactions when tagging posts in parallel. Add a hack to work around it. --- app/models/application_record.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 82850af8f..502af8603 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -168,7 +168,7 @@ class ApplicationRecord < ActiveRecord::Base concerning :ConcurrencyMethods do class_methods do - def parallel_each(batch_size: 1000, in_processes: 4, in_threads: nil) + def parallel_each(batch_size: 1000, in_processes: 4, in_threads: nil, &block) # XXX Use threads in testing because processes can't see each other's # database transactions. if Rails.env.test? @@ -176,6 +176,9 @@ class ApplicationRecord < ActiveRecord::Base in_threads = 2 end + # XXX Threads deadlock during tests if a transaction is open; do a non-parallel each. + return find_each(&block) if Rails.env.test? && connection.transaction_open? + current_user = CurrentUser.user current_ip = CurrentUser.ip_addr