X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/12495b9c8e1cbde47d0a96c021d96141c51f10d8..08d0b1ab43499b7f13462d5e3555d239b4634d22:/services/api/test/unit/container_test.rb diff --git a/services/api/test/unit/container_test.rb b/services/api/test/unit/container_test.rb index 90b4f13bf5..1a53df7dab 100644 --- a/services/api/test/unit/container_test.rb +++ b/services/api/test/unit/container_test.rb @@ -558,7 +558,8 @@ class ContainerTest < ActiveSupport::TestCase c1, _ = minimal_new(common_attrs.merge({runtime_token: api_client_authorizations(:active).token})) assert_equal Container::Queued, c1.state reused = Container.find_reusable(common_attrs.merge(runtime_token_attr(:container_runtime_token))) - assert_nil reused + # See #14584 + assert_equal c1.uuid, reused.uuid end test "find_reusable method with nil runtime_token, then runtime_token with different user" do @@ -567,7 +568,8 @@ class ContainerTest < ActiveSupport::TestCase c1, _ = minimal_new(common_attrs.merge({runtime_token: nil})) assert_equal Container::Queued, c1.state reused = Container.find_reusable(common_attrs.merge(runtime_token_attr(:container_runtime_token))) - assert_nil reused + # See #14584 + assert_equal c1.uuid, reused.uuid end test "find_reusable method with different runtime_token, different scope, same user" do @@ -576,7 +578,8 @@ class ContainerTest < ActiveSupport::TestCase c1, _ = minimal_new(common_attrs.merge({runtime_token: api_client_authorizations(:runtime_token_limited_scope).token})) assert_equal Container::Queued, c1.state reused = Container.find_reusable(common_attrs.merge(runtime_token_attr(:container_runtime_token))) - assert_nil reused + # See #14584 + assert_equal c1.uuid, reused.uuid end test "Container running" do @@ -660,6 +663,52 @@ class ContainerTest < ActiveSupport::TestCase assert_operator auth_exp, :<, db_current_time end + test "Exceed maximum lock-unlock cycles" do + Rails.configuration.max_container_dispatch_attempts = 3 + + set_user_from_auth :active + c, cr = minimal_new + + set_user_from_auth :dispatch1 + assert_equal Container::Queued, c.state + assert_equal 0, c.lock_count + + c.lock + c.reload + assert_equal 1, c.lock_count + assert_equal Container::Locked, c.state + + c.unlock + c.reload + assert_equal 1, c.lock_count + assert_equal Container::Queued, c.state + + c.lock + c.reload + assert_equal 2, c.lock_count + assert_equal Container::Locked, c.state + + c.unlock + c.reload + assert_equal 2, c.lock_count + assert_equal Container::Queued, c.state + + c.lock + c.reload + assert_equal 3, c.lock_count + assert_equal Container::Locked, c.state + + c.unlock + c.reload + assert_equal 3, c.lock_count + assert_equal Container::Cancelled, c.state + + assert_raise(ArvadosModel::LockFailedError) do + # Cancelled to Locked is not allowed + c.lock + end + end + test "Container queued cancel" do set_user_from_auth :active c, cr = minimal_new({container_count_max: 1}) @@ -674,6 +723,14 @@ class ContainerTest < ActiveSupport::TestCase assert_equal 1, Container.readable_by(users(:active)).where(state: "Queued").count end + test "Containers with no matching request are readable by admin" do + uuids = Container.includes('container_requests').where(container_requests: {uuid: nil}).collect(&:uuid) + assert_not_empty uuids + assert_empty Container.readable_by(users(:active)).where(uuid: uuids) + assert_not_empty Container.readable_by(users(:admin)).where(uuid: uuids) + assert_equal uuids.count, Container.readable_by(users(:admin)).where(uuid: uuids).count + end + test "Container locked cancel" do set_user_from_auth :active c, _ = minimal_new @@ -774,7 +831,10 @@ class ContainerTest < ActiveSupport::TestCase cr2.reload assert_equal cr1log_uuid, cr1.log_uuid assert_equal cr2log_uuid, cr2.log_uuid - assert_equal [logpdh_time2], Collection.where(uuid: [cr1log_uuid, cr2log_uuid]).to_a.collect(&:portable_data_hash).uniq + assert_equal 1, Collection.where(uuid: [cr1log_uuid, cr2log_uuid]).to_a.collect(&:portable_data_hash).uniq.length + assert_equal ". acbd18db4cc2f85cedef654fccc4a4d8+3 cdd549ae79fe6640fa3d5c6261d8303c+195 0:3:foo.txt 3:195:zzzzz-8i9sb-0vsrcqi7whchuil.log.txt +./log\\040for\\040container\\040#{cr1.container_uuid} acbd18db4cc2f85cedef654fccc4a4d8+3 cdd549ae79fe6640fa3d5c6261d8303c+195 0:3:foo.txt 3:195:zzzzz-8i9sb-0vsrcqi7whchuil.log.txt +", Collection.find_by_uuid(cr1log_uuid).manifest_text end ["auth_uuid", "runtime_token"].each do |tok|