+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
require 'test_helper'
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}}
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
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
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