14966: Implements cleanup on test case teardown.
[arvados.git] / services / api / test / integration / groups_test.rb
index 7ede5be7cc07e57d94fa8a5f20b8fcef6c50d2ea..cf0261585a9a77cdace3268918f9f4c5614bff5c 100644 (file)
@@ -1,6 +1,29 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 require 'test_helper'
 
 class GroupsTest < ActionDispatch::IntegrationTest
+  [[], ['replication_confirmed']].each do |orders|
+    test "results are consistent when provided orders #{orders} is incomplete" do
+      last = nil
+      (0..20).each do
+        get '/arvados/v1/groups/contents', {
+          id: groups(:aproject).uuid,
+          filters: [["uuid", "is_a", "arvados#collection"]].to_json,
+          orders: orders.to_json,
+          format: :json,
+        }, auth(:active)
+        assert_response :success
+        if last.nil?
+          last = json_response['items']
+        else
+          assert_equal last, json_response['items']
+        end
+      end
+    end
+  end
 
   test "get all pages of group-owned objects" do
     limit = 5
@@ -9,8 +32,6 @@ class GroupsTest < ActionDispatch::IntegrationTest
     uuid_received = {}
     owner_received = {}
     while true
-      @json_response = nil
-
       get "/arvados/v1/groups/contents", {
         id: groups(:aproject).uuid,
         limit: limit,
@@ -40,10 +61,14 @@ class GroupsTest < ActionDispatch::IntegrationTest
   end
 
   [
-    ['Collection_', true],           # collections and pipelines templates
-    ['hash', true],                  # pipeline templates
-    ['fa7aeb5140e2848d39b', true],   # script_parameter of pipeline instances
-    ['no-such-thing', false],        # script_parameter of pipeline instances
+    ['Collection_', true],            # collections and pipelines templates
+    ['hash', true],                   # pipeline templates
+    ['fa7aeb5140e2848d39b', false],   # script_parameter of pipeline instances
+    ['fa7aeb5140e2848d39b:*', true],  # script_parameter of pipeline instances
+    ['project pipeline', true],       # finds "Completed pipeline in A Project"
+    ['project pipeli:*', true],       # finds "Completed pipeline in A Project"
+    ['proje pipeli:*', false],        # first word is incomplete, so no prefix match
+    ['no-such-thing', false],         # script_parameter of pipeline instances
   ].each do |search_filter, expect_results|
     test "full text search of group-owned objects for #{search_filter}" do
       get "/arvados/v1/groups/contents", {
@@ -69,6 +94,80 @@ class GroupsTest < ActionDispatch::IntegrationTest
       :filters => [['name', '@@', 'Private']].to_json
     }, auth(:active)
     assert_response 422
-    end
+  end
 
+  test "group contents with include trash collections" do
+    get "/arvados/v1/groups/contents", {
+      include_trash: "true",
+      filters: [["uuid", "is_a", "arvados#collection"]].to_json,
+      limit: 1000
+    }, auth(:active)
+    assert_response 200
+
+    coll_uuids = []
+    json_response['items'].each { |c| coll_uuids << c['uuid'] }
+    assert_includes coll_uuids, collections(:foo_collection_in_aproject).uuid
+    assert_includes coll_uuids, collections(:expired_collection).uuid
+  end
+
+  test "group contents without trash collections" do
+    get "/arvados/v1/groups/contents", {
+      filters: [["uuid", "is_a", "arvados#collection"]].to_json,
+      limit: 1000
+    }, auth(:active)
+    assert_response 200
+
+    coll_uuids = []
+    json_response['items'].each { |c| coll_uuids << c['uuid'] }
+    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 # 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
+      },
+      async: true
+    }, auth(:active)
+    assert_response 202
+
+    # 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
+    }, auth(:active)
+    assert_response 200
+    assert_equal 0, json_response['items_available']
+
+    # Wait a bit and try again.
+    sleep(1)
+    get "/arvados/v1/groups", {
+      filters: [["name", "=", name]].to_json,
+      limit: 10
+    }, auth(:active)
+    assert_response 200
+    assert_equal 1, json_response['items_available']
+  end
 end