Merge branch '14966-api-test-hang-fix'
authorLucas Di Pentima <ldipentima@veritasgenetics.com>
Thu, 14 Mar 2019 19:42:18 +0000 (16:42 -0300)
committerLucas Di Pentima <ldipentima@veritasgenetics.com>
Thu, 14 Mar 2019 19:42:18 +0000 (16:42 -0300)
Closes #14966

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima@veritasgenetics.com>

services/api/test/integration/groups_test.rb

index 6b1bf795ed7eced1e872809358150c324e234239..cf0261585a9a77cdace3268918f9f4c5614bff5c 100644 (file)
@@ -122,11 +122,28 @@ class GroupsTest < ActionDispatch::IntegrationTest
     assert_includes coll_uuids, collections(:foo_collection_in_aproject).uuid
     assert_not_includes coll_uuids, collections(:expired_collection).uuid
   end
+end
+
+class NonTransactionalGroupsTest < ActionDispatch::IntegrationTest
+  # Transactional tests are disabled to be able to test the concurrent
+  # asynchronous permissions update feature.
+  # This is needed because nested transactions share the connection pool, so
+  # one thread is locked while trying to talk to the database, until the other
+  # one finishes.
+  self.use_transactional_fixtures = false
+
+  teardown do
+    # Explicitly reset the database after each test.
+    post '/database/reset', {}, auth(:admin)
+    assert_response :success
+  end
 
   test "create request with async=true defers permissions update" do
-    Rails.configuration.async_permissions_update_interval = 1 # seconds
+    Rails.configuration.async_permissions_update_interval = 1 # second
     name = "Random group #{rand(1000)}"
     assert_equal nil, Group.find_by_name(name)
+
+    # Trigger the asynchronous permission update by using async=true parameter.
     post "/arvados/v1/groups", {
       group: {
         name: name
@@ -134,8 +151,9 @@ class GroupsTest < ActionDispatch::IntegrationTest
       async: true
     }, auth(:active)
     assert_response 202
-    g = Group.find_by_name(name)
-    assert_not_nil g
+
+    # The group exists on the database, but it's not accessible yet.
+    assert_not_nil Group.find_by_name(name)
     get "/arvados/v1/groups", {
       filters: [["name", "=", name]].to_json,
       limit: 10
@@ -143,10 +161,8 @@ class GroupsTest < ActionDispatch::IntegrationTest
     assert_response 200
     assert_equal 0, json_response['items_available']
 
-    # Unblock the thread doing the permissions update
-    ActiveRecord::Base.clear_active_connections!
-
-    sleep(3)
+    # Wait a bit and try again.
+    sleep(1)
     get "/arvados/v1/groups", {
       filters: [["name", "=", name]].to_json,
       limit: 10