Merge branch '12690-12748-crunchstat-summary'
[arvados.git] / apps / workbench / test / controllers / container_requests_controller_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'test_helper'
6
7 class ContainerRequestsControllerTest < ActionController::TestCase
8   test "visit completed container request log tab" do
9     use_token 'active'
10
11     cr = api_fixture('container_requests')['completed']
12     container_uuid = cr['container_uuid']
13     container = Container.find(container_uuid)
14
15     get :show, {id: cr['uuid'], tab_pane: 'Log'}, session_for(:active)
16     assert_response :success
17
18     assert_select "a", {:href=>"/collections/#{container['log']}", :text=>"Download the log"}
19     assert_select "a", {:href=>"#{container['log']}/baz"}
20     assert_not_includes @response.body, '<pre id="event_log_div"'
21   end
22
23   test "visit running container request log tab" do
24     use_token 'active'
25
26     cr = api_fixture('container_requests')['running']
27     container_uuid = cr['container_uuid']
28     container = Container.find(container_uuid)
29
30     get :show, {id: cr['uuid'], tab_pane: 'Log'}, session_for(:active)
31     assert_response :success
32
33     assert_includes @response.body, '<pre id="event_log_div"'
34     assert_select 'Download the log', false
35   end
36
37   test "completed container request offers re-run option" do
38     use_token 'active'
39
40     uuid = api_fixture('container_requests')['completed']['uuid']
41
42     get :show, {id: uuid}, session_for(:active)
43     assert_response :success
44
45     assert_includes @response.body, "action=\"/container_requests/#{uuid}/copy\""
46   end
47
48   test "cancel request for queued container" do
49     cr_fixture = api_fixture('container_requests')['queued']
50     post :cancel, {id: cr_fixture['uuid']}, session_for(:active)
51     assert_response 302
52
53     use_token 'active'
54     cr = ContainerRequest.find(cr_fixture['uuid'])
55     assert_equal 'Final', cr.state
56     assert_equal 0, cr.priority
57     c = Container.find(cr_fixture['container_uuid'])
58     assert_equal 'Queued', c.state
59     assert_equal 0, c.priority
60   end
61
62   [
63     ['completed', false, false],
64     ['completed', true, false],
65     ['completed-older', false, true],
66     ['completed-older', true, true],
67   ].each do |cr_fixture, reuse_enabled, uses_acr|
68     test "container request #{uses_acr ? '' : 'not'} using arvados-cwl-runner copy #{reuse_enabled ? 'with' : 'without'} reuse enabled" do
69       completed_cr = api_fixture('container_requests')[cr_fixture]
70       # Set up post request params
71       copy_params = {id: completed_cr['uuid']}
72       if reuse_enabled
73         copy_params.merge!({use_existing: true})
74       end
75       post(:copy, copy_params, session_for(:active))
76       assert_response 302
77       copied_cr = assigns(:object)
78       assert_not_nil copied_cr
79       assert_equal 'Uncommitted', copied_cr[:state]
80       assert_equal "Copy of #{completed_cr['name']}", copied_cr['name']
81       assert_equal completed_cr['cmd'], copied_cr['cmd']
82       assert_equal completed_cr['runtime_constraints']['ram'], copied_cr['runtime_constraints'][:ram]
83       if reuse_enabled
84         assert copied_cr[:use_existing]
85       else
86         refute copied_cr[:use_existing]
87       end
88       # If the CR's command is arvados-cwl-runner, the appropriate flag should
89       # be passed to it
90       if uses_acr
91         if reuse_enabled
92           # arvados-cwl-runner's default behavior is to enable reuse
93           assert_includes copied_cr['command'], 'arvados-cwl-runner'
94           assert_not_includes copied_cr['command'], '--disable-reuse'
95         else
96           assert_includes copied_cr['command'], 'arvados-cwl-runner'
97           assert_includes copied_cr['command'], '--disable-reuse'
98           assert_not_includes copied_cr['command'], '--enable-reuse'
99         end
100       else
101         # If no arvados-cwl-runner is being used, the command should be left alone
102         assert_equal completed_cr['command'], copied_cr['command']
103       end
104     end
105   end
106
107   [
108     ['completed', true],
109     ['running', true],
110     ['queued', true],
111     ['uncommitted', false],
112   ].each do |cr_fixture, should_show|
113     test "provenance tab should #{should_show ? '' : 'not'} be shown on #{cr_fixture} container requests" do
114       cr = api_fixture('container_requests')[cr_fixture]
115       assert_not_nil cr
116       get(:show,
117           {id: cr['uuid']},
118           session_for(:active))
119       assert_response :success
120       if should_show
121         assert_includes @response.body, "href=\"#Provenance\""
122       else
123         assert_not_includes @response.body, "href=\"#Provenance\""
124       end
125     end
126   end
127
128   test "container request display" do
129     use_token 'active'
130
131     cr = api_fixture('container_requests')['completed_with_input_mounts']
132
133     get :show, {id: cr['uuid']}, session_for(:active)
134     assert_response :success
135
136     assert_match /hello/, @response.body
137     assert_includes @response.body, "href=\"\/collections/fa7aeb5140e2848d39b416daeef4ffc5+45/baz\?" # locator on command
138     assert_includes @response.body, "href=\"\/collections/fa7aeb5140e2848d39b416daeef4ffc5+45/foobar\?" # locator on command
139     assert_includes @response.body, "href=\"\/collections/fa7aeb5140e2848d39b416daeef4ffc5+45/foo" # mount input1
140     assert_includes @response.body, "href=\"\/collections/fa7aeb5140e2848d39b416daeef4ffc5+45/bar" # mount input2
141     assert_includes @response.body, "href=\"\/collections/1fd08fc162a5c6413070a8bd0bffc818+150" # mount workflow
142     assert_includes @response.body, "href=\"#Log\""
143     assert_includes @response.body, "href=\"#Provenance\""
144   end
145 end