X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/6f9bc5a295042fdcc0e51b193d3f31633d58c5d1..8100ee8f50d0c8b0340640db10745e44c0f4571b:/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 9cc098117f..edc9db66e0 100644 --- a/services/api/test/unit/container_test.rb +++ b/services/api/test/unit/container_test.rb @@ -8,6 +8,7 @@ class ContainerTest < ActiveSupport::TestCase container_image: 'img', output_path: '/tmp', priority: 1, + runtime_constraints: {"vcpus" => 1, "ram" => 1}, } def minimal_new attrs={} @@ -66,7 +67,7 @@ class ContainerTest < ActiveSupport::TestCase mounts: {"BAR" => "FOO"}, output_path: "/tmp", priority: 1, - runtime_constraints: {}) + runtime_constraints: {"vcpus" => 1, "ram" => 1}) check_illegal_modify c check_bogus_states c @@ -77,6 +78,35 @@ class ContainerTest < ActiveSupport::TestCase end end + test "Container serialized hash attributes sorted" do + env = {"C" => 3, "B" => 2, "A" => 1} + m = {"F" => 3, "E" => 2, "D" => 1} + rc = {"vcpus" => 1, "ram" => 1} + c, _ = minimal_new(environment: env, mounts: m, runtime_constraints: rc) + assert_equal c.environment.to_json, Container.deep_sort_hash(env).to_json + assert_equal c.mounts.to_json, Container.deep_sort_hash(m).to_json + assert_equal c.runtime_constraints.to_json, Container.deep_sort_hash(rc).to_json + end + + test 'deep_sort_hash on array of hashes' do + a = {'z' => [[{'a' => 'a', 'b' => 'b'}]]} + b = {'z' => [[{'b' => 'b', 'a' => 'a'}]]} + assert_equal Container.deep_sort_hash(a).to_json, Container.deep_sort_hash(b).to_json + end + + test "Container find reusable method" do + set_user_from_auth :active + c = Container.find_reusable(container_image: "test", + cwd: "test", + command: ["echo", "hello"], + output_path: "test", + runtime_constraints: {"vcpus" => 4, "ram" => 12000000000}, + mounts: {"test" => {"kind" => "json"}}, + environment: {"var" => "test"}) + assert_not_nil c + assert_equal c.uuid, containers(:completed).uuid + end + test "Container running" do c, _ = minimal_new priority: 1