16470: Avoids DB connection closing when running tests on missing places.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Mon, 20 Jul 2020 14:36:06 +0000 (11:36 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Wed, 5 Aug 2020 13:36:17 +0000 (10:36 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

services/api/lib/audit_logs.rb
services/api/lib/sweep_trashed_objects.rb

index 886c8873891c044270313e3563c73e4fe950c5cb..2b5e3b8abff2d14ddebea3008aa6774280c466f9 100644 (file)
@@ -62,7 +62,12 @@ module AuditLogs
       rescue => e
         Rails.logger.error "#{e.class}: #{e}\n#{e.backtrace.join("\n\t")}"
       ensure
-        ActiveRecord::Base.connection.close
+        # Rails 5.1+ makes test threads share a database connection, so we can't
+        # close a connection shared with other threads.
+        # https://github.com/rails/rails/commit/deba47799ff905f778e0c98a015789a1327d5087
+        if Rails.env != "test"
+          ActiveRecord::Base.connection.close
+        end
       end
     end
   end
index 8613c749cf247c6c11f309c4d43cddc544e99b4f..c09896567f3ac1291d8cbe0632393ac60d2ac8fc 100644 (file)
@@ -69,7 +69,12 @@ module SweepTrashedObjects
         rescue => e
           Rails.logger.error "#{e.class}: #{e}\n#{e.backtrace.join("\n\t")}"
         ensure
-          ActiveRecord::Base.connection.close
+          # Rails 5.1+ makes test threads share a database connection, so we can't
+          # close a connection shared with other threads.
+          # https://github.com/rails/rails/commit/deba47799ff905f778e0c98a015789a1327d5087
+          if Rails.env != "test"
+            ActiveRecord::Base.connection.close
+          end
         end
       end
     end