X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/b3f88934721fc97973b40786cae97e55e84b31d5..9ec15072e6631578584bd9c08d26025e807a8d48:/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 9a859c6229..eb4f35fea3 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 @@ -91,6 +95,42 @@ class ContainerTest < ActiveSupport::TestCase end end + test "Container valid priority" do + act_as_system_user do + c, _ = minimal_new(environment: {}, + mounts: {"BAR" => "FOO"}, + output_path: "/tmp", + priority: 1, + runtime_constraints: {"vcpus" => 1, "ram" => 1}) + + assert_raises(ActiveRecord::RecordInvalid) do + c.priority = -1 + c.save! + end + + c.priority = 0 + c.save! + + c.priority = 1 + c.save! + + c.priority = 500 + c.save! + + c.priority = 999 + c.save! + + c.priority = 1000 + c.save! + + assert_raises(ActiveRecord::RecordInvalid) do + c.priority = 1001 + c.save! + end + end + end + + test "Container serialized hash attributes sorted before save" do env = {"C" => 3, "B" => 2, "A" => 1} m = {"F" => {"kind" => 3}, "E" => {"kind" => 2}, "D" => {"kind" => 1}} @@ -340,6 +380,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 @@ -426,6 +479,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 @@ -434,6 +491,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