Merge branch '12271-fpm-cleanup-on-rpm-upgrade' closes #12271
[arvados.git] / services / api / test / unit / container_request_test.rb
index f9ce41c1e1202890fc0782c6df0333a6be8c082e..e751d6158cdc2eb1b26fd3d80fa277839d7ad590 100644 (file)
@@ -1,3 +1,7 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 require 'test_helper'
 require 'helpers/docker_migration_helper'
 
@@ -627,15 +631,15 @@ class ContainerRequestTest < ActiveSupport::TestCase
     assert_not_nil(trash)
     assert_not_nil(delete)
     assert_in_delta(trash, now + 1.second, 10)
-    assert_in_delta(delete, now + Rails.configuration.blob_signature_ttl.second, 120)
+    assert_in_delta(delete, now + Rails.configuration.blob_signature_ttl.second, 10)
   end
 
   def check_output_ttl_1y(now, trash, delete)
     year = (86400*365).second
     assert_not_nil(trash)
     assert_not_nil(delete)
-    assert_in_delta(trash, now + year, 20)
-    assert_in_delta(delete, now + year, 20)
+    assert_in_delta(trash, now + year, 10)
+    assert_in_delta(delete, now + year, 10)
   end
 
   def run_container(cr)
@@ -746,4 +750,28 @@ class ContainerRequestTest < ActiveSupport::TestCase
       end
     end
   end
+
+  test "delete container_request and check its container's priority" do
+    act_as_user users(:active) do
+      cr = ContainerRequest.find_by_uuid container_requests(:running_to_be_deleted).uuid
+
+      # initially the cr's container has priority > 0
+      c = Container.find_by_uuid(cr.container_uuid)
+      assert_equal 1, c.priority
+
+      # destroy the cr
+      assert_nothing_raised {cr.destroy}
+
+      # the cr's container now has priority of 0
+      c = Container.find_by_uuid(cr.container_uuid)
+      assert_equal 0, c.priority
+    end
+  end
+
+  test "delete container_request in final state and expect no error due to before_destroy callback" do
+    act_as_user users(:active) do
+      cr = ContainerRequest.find_by_uuid container_requests(:completed).uuid
+      assert_nothing_raised {cr.destroy}
+    end
+  end
 end