From 28e65cc5137a4e0f0a50b7c221bc1715524ac958 Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Mon, 20 Jul 2020 11:36:06 -0300 Subject: [PATCH] 16470: Avoids DB connection closing when running tests on missing places. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- services/api/lib/audit_logs.rb | 7 ++++++- services/api/lib/sweep_trashed_objects.rb | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/services/api/lib/audit_logs.rb b/services/api/lib/audit_logs.rb index 886c887389..2b5e3b8abf 100644 --- a/services/api/lib/audit_logs.rb +++ b/services/api/lib/audit_logs.rb @@ -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 diff --git a/services/api/lib/sweep_trashed_objects.rb b/services/api/lib/sweep_trashed_objects.rb index 8613c749cf..c09896567f 100644 --- a/services/api/lib/sweep_trashed_objects.rb +++ b/services/api/lib/sweep_trashed_objects.rb @@ -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 -- 2.30.2