X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/38fcd08dda022d0167840fbb65222fe99b75fcf5..ecf6627111838530f64ffcd689e11d987cc7bf2f:/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 52d2aa6741..09373fdc05 100644 --- a/services/api/test/unit/container_test.rb +++ b/services/api/test/unit/container_test.rb @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + require 'test_helper' class ContainerTest < ActiveSupport::TestCase @@ -340,6 +344,19 @@ class ContainerTest < ActiveSupport::TestCase assert_nil reused end + test "find_reusable with logging disabled" do + set_user_from_auth :active + Rails.logger.expects(:info).never + Container.find_reusable(REUSABLE_COMMON_ATTRS) + end + + test "find_reusable with logging enabled" do + set_user_from_auth :active + Rails.configuration.log_reuse_decisions = true + Rails.logger.expects(:info).at_least(3) + Container.find_reusable(REUSABLE_COMMON_ATTRS) + end + test "Container running" do c, _ = minimal_new priority: 1 @@ -365,7 +382,10 @@ class ContainerTest < ActiveSupport::TestCase set_user_from_auth :dispatch1 assert_equal Container::Queued, c.state - assert_raise(ActiveRecord::RecordInvalid) {c.lock} # "no priority" + assert_raise(ArvadosModel::LockFailedError) do + # "no priority" + c.lock + end c.reload assert cr.update_attributes priority: 1 @@ -378,7 +398,7 @@ class ContainerTest < ActiveSupport::TestCase assert c.locked_by_uuid assert c.auth_uuid - assert_raise(ArvadosModel::AlreadyLockedError) {c.lock} + assert_raise(ArvadosModel::LockFailedError) {c.lock} c.reload assert c.unlock, show_errors(c) @@ -397,9 +417,15 @@ class ContainerTest < ActiveSupport::TestCase auth_uuid_was = c.auth_uuid - assert_raise(ActiveRecord::RecordInvalid) {c.lock} # Running to Locked is not allowed + assert_raise(ArvadosModel::LockFailedError) do + # Running to Locked is not allowed + c.lock + end c.reload - assert_raise(ActiveRecord::RecordInvalid) {c.unlock} # Running to Queued is not allowed + assert_raise(ArvadosModel::InvalidStateTransitionError) do + # Running to Queued is not allowed + c.unlock + end c.reload assert c.update_attributes(state: Container::Complete), show_errors(c) @@ -417,6 +443,10 @@ class ContainerTest < ActiveSupport::TestCase check_no_change_from_cancelled c end + test "Container queued count" do + assert_equal 1, Container.readable_by(users(:active)).where(state: "Queued").count + end + test "Container locked cancel" do c, _ = minimal_new set_user_from_auth :dispatch1 @@ -425,6 +455,17 @@ class ContainerTest < ActiveSupport::TestCase check_no_change_from_cancelled c end + test "Container locked cancel with log" do + c, _ = minimal_new + set_user_from_auth :dispatch1 + assert c.lock, show_errors(c) + assert c.update_attributes( + state: Container::Cancelled, + log: collections(:real_log_collection).portable_data_hash, + ), show_errors(c) + check_no_change_from_cancelled c + end + test "Container running cancel" do c, _ = minimal_new set_user_from_auth :dispatch1