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
17 def fakepipe_with_log_data
19 "2014-01-01_12:00:01 zzzzz-8i9sb-0vsrcqi7whchuil 0 log message 1\n" +
20 "2014-01-01_12:00:02 zzzzz-8i9sb-0vsrcqi7whchuil 0 log message 2\n" +
21 "2014-01-01_12:00:03 zzzzz-8i9sb-0vsrcqi7whchuil 0 log message 3\n"
22 StringIO.new content, 'r'
25 test "add job description" do
26 job = api_fixture('jobs')['nearly_finished_job']
27 visit page_with_token("active", "/jobs/#{job['uuid']}")
29 # edit job description
30 within('.arv-description-as-subtitle') do
31 find('.fa-pencil').click
32 find('.editable-input textarea').set('*Textile description for job* - "Go to dashboard":/')
33 find('.editable-submit').click
36 # Verify edited description
37 assert_no_text '*Textile description for job*'
38 assert_text 'Textile description for job'
39 assert_selector 'a[href="/"]', text: 'Go to dashboard'
42 test 'view partial job log' do
43 need_selenium 'to be able to see the CORS response headers (PhantomJS 1.9.8 does not)'
46 # This config will be restored during teardown by ../test_helper.rb:
47 Rails.configuration.log_viewer_max_bytes = 100
49 logdata = fakepipe_with_log_data.read
50 job_uuid = api_fixture('jobs')['running']['uuid']
51 logcollection = upload_data_and_get_collection(logdata, 'active', "#{job_uuid}.log.txt")
54 job = Job.find job_uuid
55 job.update_attributes log: logcollection.portable_data_hash
57 visit page_with_token 'active', '/jobs/'+job.uuid
58 find('a[href="#Log"]').click
60 assert_text 'Showing only 100 bytes of this log'
63 test 'view log via keep-web redirect' do
66 token = api_token('active')
67 logdata = fakepipe_with_log_data.read
68 logblock = `echo -n #{logdata.shellescape} | ARVADOS_API_TOKEN=#{token.shellescape} arv-put --no-progress --raw -`.strip
69 assert $?.success?, $?
73 job = Job.find api_fixture('jobs')['running']['uuid']
74 mtxt = ". #{logblock} 0:#{logdata.length}:#{job.uuid}.log.txt\n"
75 logcollection = Collection.create(manifest_text: mtxt)
76 job.update_attributes log: logcollection.portable_data_hash
78 visit page_with_token 'active', '/jobs/'+job.uuid
79 find('a[href="#Log"]').click
80 assert_text 'log message 1'
84 ['foobar', false, false],
85 ['job_with_latest_version', true, false],
86 ['job_with_latest_version', true, true],
87 ].each do |job_name, expect_options, use_latest|
88 test "Rerun #{job_name} job, expect options #{expect_options},
89 and use latest version option #{use_latest}" do
90 job = api_fixture('jobs')[job_name]
91 visit page_with_token 'active', '/jobs/'+job['uuid']
94 assert_text 'supplied_script_version: master'
96 assert_no_text 'supplied_script_version'
99 assert_triggers_dom_event 'shown.bs.modal' do
100 find('a,button', text: 'Re-run job...').click
102 within('.modal-dialog') do
103 assert_selector 'a,button', text: 'Cancel'
105 page.choose("job_script_version_#{job['supplied_script_version']}")
110 # Re-running jobs doesn't currently work because the test API
111 # server has no git repository to check against. For now, check
112 # that the error message says something appropriate for that
114 if expect_options && use_latest
115 assert_text "077ba2ad3ea24a929091a9e6ce545c93199b8e57"
117 assert_text "Script version #{job['script_version']} does not resolve to a commit"
124 ['job_reader2', false],
125 ].each do |user, readable|
126 test "view job with components as #{user} user" do
127 job = api_fixture('jobs')['running_job_with_components']
128 component1 = api_fixture('jobs')['completed_job_in_publicly_accessible_project']
129 component2 = api_fixture('pipeline_instances')['running_pipeline_with_complete_job']
130 component2_child1 = api_fixture('jobs')['previous_job_run']
131 component2_child2 = api_fixture('jobs')['running']
133 visit page_with_token(user, "/jobs/#{job['uuid']}")
134 assert page.has_text? job['script_version']
135 assert page.has_no_text? 'script_parameters'
137 # The job_reader2 is allowed to read job, component2, and component2_child1,
138 # and component2_child2 only as a component of the pipeline component2
140 assert page.has_link? 'component1'
141 assert page.has_link? 'component2'
143 assert page.has_no_link? 'component1'
144 assert page.has_link? 'component2'
148 click_link('component1')
149 within('.panel-collapse') do
150 assert(has_text? component1['uuid'])
151 assert(has_text? component1['script_version'])
152 assert(has_text? 'script_parameters')
154 click_link('component1')
157 click_link('component2')
158 within('.panel-collapse') do
159 assert(has_text? component2['uuid'])
160 assert(has_text? component2['script_version'])
161 assert(has_no_text? 'script_parameters')
162 assert(has_link? 'previous')
163 assert(has_link? 'running')
165 click_link('previous')
166 within('.panel-collapse') do
167 assert(has_text? component2_child1['uuid'])
168 assert(has_text? component2_child1['script_version'])
170 click_link('previous')
172 click_link('running')
173 within('.panel-collapse') do
174 assert(has_text? component2_child2['uuid'])
176 assert(has_text? component2_child2['script_version'])
178 assert(has_no_text? component2_child2['script_version'])