20032: Fix unnecessary race in test.
[arvados.git] / apps / workbench / test / controllers / container_requests_controller_test.rb
index 554aaf6d041324445e1017bdf7e17df94c5b7e0a..c8709df3c35154e172898e060a9cb526196ef064 100644 (file)
@@ -1,3 +1,7 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 require 'test_helper'
 
 class ContainerRequestsControllerTest < ActionController::TestCase
@@ -8,12 +12,12 @@ class ContainerRequestsControllerTest < ActionController::TestCase
     container_uuid = cr['container_uuid']
     container = Container.find(container_uuid)
 
-    get :show, {id: cr['uuid'], tab_pane: 'Log'}, session_for(:active)
+    get :show, params: {id: cr['uuid'], tab_pane: 'Log'}, session: session_for(:active)
     assert_response :success
 
     assert_select "a", {:href=>"/collections/#{container['log']}", :text=>"Download the log"}
     assert_select "a", {:href=>"#{container['log']}/baz"}
-    assert_not_includes @response.body, '<div id="event_log_div"'
+    assert_not_includes @response.body, '<pre id="event_log_div"'
   end
 
   test "visit running container request log tab" do
@@ -23,10 +27,10 @@ class ContainerRequestsControllerTest < ActionController::TestCase
     container_uuid = cr['container_uuid']
     container = Container.find(container_uuid)
 
-    get :show, {id: cr['uuid'], tab_pane: 'Log'}, session_for(:active)
+    get :show, params: {id: cr['uuid'], tab_pane: 'Log'}, session: session_for(:active)
     assert_response :success
 
-    assert_includes @response.body, '<div id="event_log_div"'
+    assert_includes @response.body, '<pre id="event_log_div"'
     assert_select 'Download the log', false
   end
 
@@ -35,32 +39,47 @@ class ContainerRequestsControllerTest < ActionController::TestCase
 
     uuid = api_fixture('container_requests')['completed']['uuid']
 
-    get :show, {id: uuid}, session_for(:active)
+    get :show, params: {id: uuid}, session: session_for(:active)
     assert_response :success
 
-   assert_includes @response.body, "action=\"/container_requests/#{uuid}/copy\""
+    assert_includes @response.body, "action_href=%2Fcontainer_requests%2F#{uuid}%2Fcopy"
+  end
+
+  test "cancel request for queued container" do
+    cr_fixture = api_fixture('container_requests')['queued']
+    post :cancel, params: {id: cr_fixture['uuid']}, session: session_for(:active)
+    assert_response 302
+
+    use_token 'active'
+    cr = ContainerRequest.find(cr_fixture['uuid'])
+    assert_equal 'Final', cr.state
+    assert_equal 0, cr.priority
+    c = Container.find(cr_fixture['container_uuid'])
+    assert_equal 'Queued', c.state
+    assert_equal 0, c.priority
   end
 
   [
-    ['completed', false, false],
-    ['completed', true, false],
+    ['completed',       false, false],
+    ['completed',        true, false],
+    ['completed',         nil, false],
     ['completed-older', false, true],
-    ['completed-older', true, true],
+    ['completed-older',  true, true],
+    ['completed-older',   nil, true],
   ].each do |cr_fixture, reuse_enabled, uses_acr|
-    test "container request #{uses_acr ? '' : 'not'} using arvados-cwl-runner copy #{reuse_enabled ? 'with' : 'without'} reuse enabled" do
+    test "container request #{uses_acr ? '' : 'not'} using arvados-cwl-runner copy #{reuse_enabled.nil? ? 'nil' : (reuse_enabled ? 'with' : 'without')} reuse enabled" do
       completed_cr = api_fixture('container_requests')[cr_fixture]
       # Set up post request params
       copy_params = {id: completed_cr['uuid']}
-      if reuse_enabled
-        copy_params.merge!({use_existing: true})
+      if !reuse_enabled.nil?
+        copy_params.merge!({use_existing: reuse_enabled})
       end
-      post(:copy, copy_params, session_for(:active))
+      post(:copy, params: copy_params, session: session_for(:active))
       assert_response 302
       copied_cr = assigns(:object)
       assert_not_nil copied_cr
       assert_equal 'Uncommitted', copied_cr[:state]
       assert_equal "Copy of #{completed_cr['name']}", copied_cr['name']
-      assert_equal completed_cr['cmd'], copied_cr['cmd']
       assert_equal completed_cr['runtime_constraints']['ram'], copied_cr['runtime_constraints'][:ram]
       if reuse_enabled
         assert copied_cr[:use_existing]
@@ -70,12 +89,11 @@ class ContainerRequestsControllerTest < ActionController::TestCase
       # If the CR's command is arvados-cwl-runner, the appropriate flag should
       # be passed to it
       if uses_acr
-        if reuse_enabled
-          # arvados-cwl-runner's default behavior is to enable reuse
-          assert_includes copied_cr['command'], 'arvados-cwl-runner'
+        assert_equal copied_cr['command'][0], 'arvados-cwl-runner'
+        if reuse_enabled.nil? || reuse_enabled
+          assert_includes copied_cr['command'], '--enable-reuse'
           assert_not_includes copied_cr['command'], '--disable-reuse'
         else
-          assert_includes copied_cr['command'], 'arvados-cwl-runner'
           assert_includes copied_cr['command'], '--disable-reuse'
           assert_not_includes copied_cr['command'], '--enable-reuse'
         end
@@ -96,8 +114,8 @@ class ContainerRequestsControllerTest < ActionController::TestCase
       cr = api_fixture('container_requests')[cr_fixture]
       assert_not_nil cr
       get(:show,
-          {id: cr['uuid']},
-          session_for(:active))
+          params: {id: cr['uuid']},
+          session: session_for(:active))
       assert_response :success
       if should_show
         assert_includes @response.body, "href=\"#Provenance\""
@@ -112,13 +130,14 @@ class ContainerRequestsControllerTest < ActionController::TestCase
 
     cr = api_fixture('container_requests')['completed_with_input_mounts']
 
-    get :show, {id: cr['uuid']}, session_for(:active)
+    get :show, params: {id: cr['uuid']}, session: session_for(:active)
     assert_response :success
 
     assert_match /hello/, @response.body
+    assert_includes @response.body, "href=\"\/collections/fa7aeb5140e2848d39b416daeef4ffc5+45/baz\?" # locator on command
+    assert_includes @response.body, "href=\"\/collections/fa7aeb5140e2848d39b416daeef4ffc5+45/foobar\?" # locator on command
     assert_includes @response.body, "href=\"\/collections/fa7aeb5140e2848d39b416daeef4ffc5+45/foo" # mount input1
     assert_includes @response.body, "href=\"\/collections/fa7aeb5140e2848d39b416daeef4ffc5+45/bar" # mount input2
-    assert_includes @response.body, "href=\"\/collections/1fd08fc162a5c6413070a8bd0bffc818+150" # mount workflow
     assert_includes @response.body, "href=\"#Log\""
     assert_includes @response.body, "href=\"#Provenance\""
   end