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)'
44 # This config will be restored during teardown by ../test_helper.rb:
45 Rails.configuration.Workbench.LogViewerMaxBytes = 100
47 logdata = fakepipe_with_log_data.read
48 job_uuid = api_fixture('jobs')['running']['uuid']
49 logcollection = upload_data_and_get_collection(logdata, 'active', "#{job_uuid}.log.txt")
52 job = Job.find job_uuid
53 job.update_attributes log: logcollection.portable_data_hash
55 visit page_with_token 'active', '/jobs/'+job.uuid
56 find('a[href="#Log"]').click
58 assert_text 'Showing only 100 bytes of this log'
61 test 'view log via keep-web redirect' do
64 token = api_token('active')
65 logdata = fakepipe_with_log_data.read
66 logblock = `echo -n #{logdata.shellescape} | ARVADOS_API_TOKEN=#{token.shellescape} arv-put --no-progress --raw -`.strip
67 assert $?.success?, $?
71 job = Job.find api_fixture('jobs')['running']['uuid']
72 mtxt = ". #{logblock} 0:#{logdata.length}:#{job.uuid}.log.txt\n"
73 logcollection = Collection.create(manifest_text: mtxt)
74 job.update_attributes log: logcollection.portable_data_hash
76 visit page_with_token 'active', '/jobs/'+job.uuid
77 find('a[href="#Log"]').click
78 assert_text 'log message 1'
82 ['foobar', false, false],
83 ['job_with_latest_version', true, false],
84 ['job_with_latest_version', true, true],
85 ].each do |job_name, expect_options, use_latest|
86 test "Rerun #{job_name} job, expect options #{expect_options},
87 and use latest version option #{use_latest}" do
88 job = api_fixture('jobs')[job_name]
89 visit page_with_token 'active', '/jobs/'+job['uuid']
92 assert_text 'supplied_script_version: master'
94 assert_no_text 'supplied_script_version'
97 assert_triggers_dom_event 'shown.bs.modal' do
98 find('a,button', text: 'Re-run job...').click
100 within('.modal-dialog') do
101 assert_selector 'a,button', text: 'Cancel'
103 page.choose("job_script_version_#{job['supplied_script_version']}")
108 # Re-running jobs doesn't currently work because the test API
109 # server has no git repository to check against. For now, check
110 # that the error message says something appropriate for that
112 if expect_options && use_latest
113 assert_text "077ba2ad3ea24a929091a9e6ce545c93199b8e57"
115 assert_text "Script version #{job['script_version']} does not resolve to a commit"
122 ['job_reader2', false],
123 ].each do |user, readable|
124 test "view job with components as #{user} user" do
125 job = api_fixture('jobs')['running_job_with_components']
126 component1 = api_fixture('jobs')['completed_job_in_publicly_accessible_project']
127 component2 = api_fixture('pipeline_instances')['running_pipeline_with_complete_job']
128 component2_child1 = api_fixture('jobs')['previous_job_run']
129 component2_child2 = api_fixture('jobs')['running']
131 visit page_with_token(user, "/jobs/#{job['uuid']}")
132 assert page.has_text? job['script_version']
133 assert page.has_no_text? 'script_parameters'
135 # The job_reader2 is allowed to read job, component2, and component2_child1,
136 # and component2_child2 only as a component of the pipeline component2
138 assert page.has_link? 'component1'
139 assert page.has_link? 'component2'
141 assert page.has_no_link? 'component1'
142 assert page.has_link? 'component2'
146 click_link('component1')
147 within('.panel-collapse') do
148 assert(has_text? component1['uuid'])
149 assert(has_text? component1['script_version'])
150 assert(has_text? 'script_parameters')
152 click_link('component1')
155 click_link('component2')
156 within('.panel-collapse') do
157 assert(has_text? component2['uuid'])
158 assert(has_text? component2['script_version'])
159 assert(has_no_text? 'script_parameters')
160 assert(has_link? 'previous')
161 assert(has_link? 'running')
163 click_link('previous')
164 within('.panel-collapse') do
165 assert(has_text? component2_child1['uuid'])
166 assert(has_text? component2_child1['script_version'])
168 click_link('previous')
170 click_link('running')
171 within('.panel-collapse') do
172 assert(has_text? component2_child2['uuid'])
174 assert(has_text? component2_child2['script_version'])
176 assert(has_no_text? component2_child2['script_version'])