9388: Add ws.notify_queue to ensure that notifies occurring during "catch up"
[arvados.git] / services / api / test / unit / container_request_test.rb
index 74c230c21073bdc75fed3ef430bf16c677504f32..701147cf6576997c04bf633650b0770c193136ee 100644 (file)
@@ -237,19 +237,19 @@ class ContainerRequestTest < ActiveSupport::TestCase
     cr.priority = 5
     cr.save!
 
-    c2 = ContainerRequest.new
-    c2.state = "Committed"
-    c2.container_image = "img"
-    c2.command = ["foo", "bar"]
-    c2.output_path = "/tmp"
-    c2.cwd = "/tmp"
-    c2.priority = 10
-    c2.save!
+    cr2 = ContainerRequest.new
+    cr2.state = "Committed"
+    cr2.container_image = "img"
+    cr2.command = ["foo", "bar"]
+    cr2.output_path = "/tmp"
+    cr2.cwd = "/tmp"
+    cr2.priority = 10
+    cr2.save!
 
     c = Container.find_by_uuid cr.container_uuid
     assert_equal 5, c.priority
 
-    c2 = Container.find_by_uuid c2.container_uuid
+    c2 = Container.find_by_uuid cr2.container_uuid
     assert_equal 10, c2.priority
 
     cr.priority = 0
@@ -306,18 +306,18 @@ class ContainerRequestTest < ActiveSupport::TestCase
     assert_equal "Committed", cr.state
 
     c = Container.find_by_uuid cr.container_uuid
-    assert_equal "Queued", c.state
+    assert_equal Container::Queued, c.state
 
     act_as_system_user do
-      c.state = "Running"
-      c.save!
+      c.update_attributes! state: Container::Locked
+      c.update_attributes! state: Container::Running
     end
 
     cr.reload
     assert_equal "Committed", cr.state
 
     act_as_system_user do
-      c.state = "Complete"
+      c.update_attributes! state: Container::Complete
       c.save!
     end
 
@@ -326,4 +326,46 @@ class ContainerRequestTest < ActiveSupport::TestCase
 
   end
 
+  test "Container makes container request, then is cancelled" do
+    set_user_from_auth :active_trustedclient
+    cr = ContainerRequest.new
+    cr.state = "Committed"
+    cr.container_image = "img"
+    cr.command = ["foo", "bar"]
+    cr.output_path = "/tmp"
+    cr.cwd = "/tmp"
+    cr.priority = 5
+    cr.save!
+
+    c = Container.find_by_uuid cr.container_uuid
+    assert_equal 5, c.priority
+
+    cr2 = ContainerRequest.new
+    cr2.state = "Committed"
+    cr2.container_image = "img"
+    cr2.command = ["foo", "bar"]
+    cr2.output_path = "/tmp"
+    cr2.cwd = "/tmp"
+    cr2.priority = 10
+    cr2.requesting_container_uuid = c.uuid
+    cr2.save!
+
+    c2 = Container.find_by_uuid cr2.container_uuid
+    assert_equal 10, c2.priority
+
+    act_as_system_user do
+      c.state = "Cancelled"
+      c.save!
+    end
+
+    cr.reload
+    assert_equal "Final", cr.state
+
+    cr2.reload
+    assert_equal 0, cr2.priority
+
+    c2.reload
+    assert_equal 0, c2.priority
+  end
+
 end