X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/f4ca9ad94a6bb006d1f3c7ba207837f1736d1247..0e9aa62c7865f092917d3d46b0de4a3dd453b672:/services/api/test/integration/groups_test.rb diff --git a/services/api/test/integration/groups_test.rb b/services/api/test/integration/groups_test.rb index 2afece9563..130801bd9f 100644 --- a/services/api/test/integration/groups_test.rb +++ b/services/api/test/integration/groups_test.rb @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + require 'test_helper' class GroupsTest < ActionDispatch::IntegrationTest @@ -91,4 +95,79 @@ class GroupsTest < ActionDispatch::IntegrationTest }, auth(:active) assert_response 422 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. + # + # WARNING: Any test within this class should clean up the changes made in the + # database to avoid state leaks to other tests! + self.use_transactional_fixtures = false + + 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 accesible 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'] + + # Clean up after ourselves + Group.find_by_uuid(json_response['items'][0]['uuid']).destroy + end end