16470: Fixes tests. Avoids closing a DB connection when using threads on tests.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Wed, 15 Jul 2020 14:14:09 +0000 (11:14 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Wed, 5 Aug 2020 13:36:17 +0000 (10:36 -0300)
From Rails 5.1, test threads share a database connection, so UpdatePriority
won't try to close DB connections when running from tests.

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

services/api/lib/update_priority.rb
services/api/test/functional/arvados/v1/keep_services_controller_test.rb

index c688ac008b44b21944e86b36cdb3abbb15273e12..3a65c71fe9453979070b0e6f1fdae37054aa2bd8 100644 (file)
@@ -55,7 +55,12 @@ module UpdatePriority
       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 ce1d447f16ad0f950327ecfa1e47f7cb24fcd76f..0fbc7625ceb0d985d4c26d10e9cc2b636574378e 100644 (file)
@@ -50,8 +50,7 @@ class Arvados::V1::KeepServicesControllerTest < ActionController::TestCase
     refute_empty expect_rvz
     authorize_with :active
     get :index,
-      params: {:format => :json},
-      headers: auth(:active)
+      params: {:format => :json}
     assert_response :success
     json_response['items'].each do |svc|
       url = "#{svc['service_ssl_flag'] ? 'https' : 'http'}://#{svc['service_host']}:#{svc['service_port']}/"