1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
8 require 'integration_helper'
10 class JobsTest < ActionDispatch::IntegrationTest
15 def fakepipe_with_log_data
17 "2014-01-01_12:00:01 zzzzz-8i9sb-0vsrcqi7whchuil 0 log message 1\n" +
18 "2014-01-01_12:00:02 zzzzz-8i9sb-0vsrcqi7whchuil 0 log message 2\n" +
19 "2014-01-01_12:00:03 zzzzz-8i9sb-0vsrcqi7whchuil 0 log message 3\n"
20 StringIO.new content, 'r'
23 test "add job description" do
24 job = api_fixture('jobs')['nearly_finished_job']
25 visit page_with_token("active", "/jobs/#{job['uuid']}")
27 # edit job description
28 within('.arv-description-as-subtitle') do
29 find('.fa-pencil').click
30 find('.editable-input textarea').set('*Textile description for job* - "Go to dashboard":/')
31 find('.editable-submit').click
34 # Verify edited description
35 assert_no_text '*Textile description for job*'
36 assert_text 'Textile description for job'
37 assert_selector 'a[href="/"]', text: 'Go to dashboard'
40 test 'view partial job log' do
41 need_selenium 'to be able to see the CORS response headers (PhantomJS 1.9.8 does not)'
43 # This config will be restored during teardown by ../test_helper.rb:
44 Rails.configuration.Workbench.LogViewerMaxBytes = 100
46 logdata = fakepipe_with_log_data.read
47 job_uuid = api_fixture('jobs')['running']['uuid']
48 logcollection = upload_data_and_get_collection(logdata, 'active', "#{job_uuid}.log.txt")
51 job = Job.find job_uuid
52 job.update_attributes log: logcollection.portable_data_hash
54 visit page_with_token 'active', '/jobs/'+job.uuid
55 find('a[href="#Log"]').click
57 assert_text 'Showing only 100 bytes of this log'
60 test 'view log via keep-web redirect' do
61 token = api_token('active')
62 logdata = fakepipe_with_log_data.read
63 logblock = `echo -n #{logdata.shellescape} | ARVADOS_API_TOKEN=#{token.shellescape} arv-put --no-progress --raw -`.strip
64 assert $?.success?, $?
68 job = Job.find api_fixture('jobs')['running']['uuid']
69 mtxt = ". #{logblock} 0:#{logdata.length}:#{job.uuid}.log.txt\n"
70 logcollection = Collection.create(manifest_text: mtxt)
71 job.update_attributes log: logcollection.portable_data_hash
73 visit page_with_token 'active', '/jobs/'+job.uuid
74 find('a[href="#Log"]').click
75 assert_text 'log message 1'
79 ['foobar', false, false],
80 ['job_with_latest_version', true, false],
81 ['job_with_latest_version', true, true],
82 ].each do |job_name, expect_options, use_latest|
83 test "Rerun #{job_name} job, expect options #{expect_options},
84 and use latest version option #{use_latest}" do
85 job = api_fixture('jobs')[job_name]
86 visit page_with_token 'active', '/jobs/'+job['uuid']
89 assert_text 'supplied_script_version: master'
91 assert_no_text 'supplied_script_version'
94 assert_triggers_dom_event 'shown.bs.modal' do
95 find('a,button', text: 'Re-run job...').click
97 within('.modal-dialog') do
98 assert_selector 'a,button', text: 'Cancel'
100 page.choose("job_script_version_#{job['supplied_script_version']}")
105 # Re-running jobs doesn't currently work because the test API
106 # server has no git repository to check against. For now, check
107 # that the error message says something appropriate for that
109 if expect_options && use_latest
110 assert_text "077ba2ad3ea24a929091a9e6ce545c93199b8e57"
112 assert_text "Script version #{job['script_version']} does not resolve to a commit"
119 ['job_reader2', false],
120 ].each do |user, readable|
121 test "view job with components as #{user} user" do
122 Rails.configuration.Users.AnonymousUserToken = ""
123 job = api_fixture('jobs')['running_job_with_components']
124 component1 = api_fixture('jobs')['completed_job_in_publicly_accessible_project']
125 component2 = api_fixture('pipeline_instances')['running_pipeline_with_complete_job']
126 component2_child1 = api_fixture('jobs')['previous_job_run']
127 component2_child2 = api_fixture('jobs')['running']
129 visit page_with_token(user, "/jobs/#{job['uuid']}")
130 assert page.has_text? job['script_version']
131 assert page.has_no_text? 'script_parameters'
133 # The job_reader2 is allowed to read job, component2, and component2_child1,
134 # and component2_child2 only as a component of the pipeline component2
136 assert page.has_link? 'component1'
137 assert page.has_link? 'component2'
139 assert page.has_no_link? 'component1'
140 assert page.has_link? 'component2'
144 click_link('component1')
145 within('.panel-collapse') do
146 assert(has_text? component1['uuid'])
147 assert(has_text? component1['script_version'])
148 assert(has_text? 'script_parameters')
150 click_link('component1')
153 click_link('component2')
154 within('.panel-collapse') do
155 assert(has_text? component2['uuid'])
156 assert(has_text? component2['script_version'])
157 assert(has_no_text? 'script_parameters')
158 assert(has_link? 'previous')
159 assert(has_link? 'running')
161 click_link('previous')
162 within('.panel-collapse') do
163 assert(has_text? component2_child1['uuid'])
164 assert(has_text? component2_child1['script_version'])
166 click_link('previous')
168 click_link('running')
169 within('.panel-collapse') do
170 assert(has_text? component2_child2['uuid'])
172 assert(has_text? component2_child2['script_version'])
174 assert(has_no_text? component2_child2['script_version'])