1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 require 'integration_helper'
7 class PipelineInstancesTest < ActionDispatch::IntegrationTest
12 def parse_browser_timestamp t
13 # Timestamps are displayed in the browser's time zone (which can
14 # differ from ours) and they come from toLocaleTimeString (which
15 # means they don't necessarily tell us which time zone they're
16 # using). In order to make sense of them, we need to ask the
17 # browser to parse them and generate a timestamp that can be
20 # Note: Even with all this help, phantomjs seem to behave badly
21 # when parsing timestamps on the other side of a DST transition.
22 # See skipped tests below.
24 # In some locales (e.g., en_CA.UTF-8) Firefox can't parse what its
25 # own toLocaleString() puts out.
26 t.sub!(/(\d\d\d\d)-(\d\d)-(\d\d)/, '\2/\3/\1')
28 if /(\d+:\d+ [AP]M) (\d+\/\d+\/\d+)/ =~ t
29 # Currently dates.js renders timestamps as
30 # '{t.toLocaleTimeString()} {t.toLocaleDateString()}' which even
31 # en_US browsers can't make sense of. First we need to flip it
32 # around so it looks like what toLocaleString() would have made.
33 t = $~[2] + ', ' + $~[1]
36 utc = page.evaluate_script("new Date('#{t}').toUTCString()")
37 DateTime.parse(utc).to_time
41 # No need to test (or mention) these all the time. If they start
42 # working (without need_selenium) then some real tests might not
43 # need_selenium any more.
45 test 'phantomjs DST' do
47 t0s = '3/8/2015, 01:59 AM'
48 t1s = '3/8/2015, 03:01 AM'
49 t0 = parse_browser_timestamp t0s
50 t1 = parse_browser_timestamp t1s
51 assert_equal 120, t1-t0, "'#{t0s}' to '#{t1s}' was reported as #{t1-t0} seconds, should be 120"
54 test 'phantomjs DST 2' do
56 t0s = '2015-03-08T10:43:00Z'
57 t1s = '2015-03-09T03:43:00Z'
58 t0 = parse_browser_timestamp page.evaluate_script("new Date('#{t0s}').toLocaleString()")
59 t1 = parse_browser_timestamp page.evaluate_script("new Date('#{t1s}').toLocaleString()")
60 assert_equal 17*3600, t1-t0, "'#{t0s}' to '#{t1s}' was reported as #{t1-t0} seconds, should be #{17*3600} (17 hours)"
64 test 'Create and run a pipeline' do
65 visit page_with_token('active_trustedclient', '/pipeline_templates')
66 within('tr', text: 'Two Part Pipeline Template') do
67 find('a,button', text: 'Run').click
71 within('.modal-dialog') do #FIXME: source of 1 test error
72 find('.selectable', text: 'A Project').click
73 find('button', text: 'Choose').click
76 # This pipeline needs input. So, Run should be disabled
77 page.assert_selector 'a.disabled,button.disabled', text: 'Run'
79 instance_page = current_path
81 # Add this collection to the project
83 find("#projects-menu").click
84 find('.dropdown-menu a,button', text: 'A Project').click
85 find('.btn', text: 'Add data').click
86 find('.dropdown-menu a,button', text: 'Copy data from another project').click
87 within('.modal-dialog') do
89 first('span', text: 'foo_tag').click
90 find('.btn', text: 'Copy').click
92 using_wait_time(Capybara.default_max_wait_time * 3) do
96 click_link 'Pipelines and processes'
97 find('tr[data-kind="arvados#pipelineInstance"]', text: '(none)').
98 find('a', text: 'Show').
101 assert find('p', text: 'Provide a value')
103 find('div.form-group', text: 'Foo/bar pair').
104 find('.btn', text: 'Choose').
107 within('.modal-dialog') do
108 assert(has_text?("Foo/bar pair"),
109 "pipeline input picker missing name of input")
111 first('span', text: 'foo_tag').click
112 find('button', text: 'OK').click
116 # The input, after being specified, should still be displayed (#3382)
117 assert find('div.form-group', text: 'Foo/bar pair')
119 # The input, after being specified, should still be editable (#3382)
120 find('div.form-group', text: 'Foo/bar pair').
121 find('.btn', text: 'Choose').click
123 within('.modal-dialog') do
124 assert(has_text?("Foo/bar pair"),
125 "pipeline input picker missing name of input")
127 first('span', text: 'foo_tag').click
128 find('button', text: 'OK').click
131 # For good measure, check one last time that the input, after being specified twice, is still be displayed (#3382)
132 assert find('div.form-group', text: 'Foo/bar pair')
134 # Ensure that the collection's portable_data_hash, uuid and name
135 # are saved in the desired places. (#4015)
137 # foo_collection_in_aproject is the collection tagged with foo_tag.
138 collection = api_fixture('collections', 'foo_collection_in_aproject')
139 click_link 'Advanced'
140 click_link 'API response'
141 api_response = JSON.parse(find('div#advanced_api_response pre').text)
142 input_params = api_response['components']['part-one']['script_parameters']['input']
143 assert_equal input_params['value'], collection['portable_data_hash']
144 assert_equal input_params['selection_name'], collection['name']
145 assert_equal input_params['selection_uuid'], collection['uuid']
147 # "Run" button is now enabled
148 page.assert_no_selector 'a.disabled,button.disabled', text: 'Run'
150 first('a,button', text: 'Run').click
152 # Pipeline is running. We have a "Pause" button instead now.
153 page.assert_selector 'a,button', text: 'Pause'
154 find('a,button', text: 'Pause').click
156 # Pipeline is stopped. It should now be in paused state and Runnable again.
157 assert page.has_text? 'Paused'
158 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
159 page.assert_selector 'a,button', text: 'Re-run with latest'
160 page.assert_selector 'a,button', text: 'Re-run options'
162 # Since it is test env, no jobs are created to run. So, graph not visible
163 assert page.has_no_text? 'Graph'
166 # Create a pipeline instance from within a project and run
167 test 'Create pipeline inside a project and run' do
168 visit page_with_token('active_trustedclient', '/projects')
170 # Add collection to the project using Add data button
171 find("#projects-menu").click
172 find('.dropdown-menu a,button', text: 'A Project').click
173 find('.btn', text: 'Add data').click
174 find('.dropdown-menu a,button', text: 'Copy data from another project').click
175 within('.modal-dialog') do
177 first('span', text: 'foo_tag').click
178 find('.btn', text: 'Copy').click
180 using_wait_time(Capybara.default_max_wait_time * 3) do
184 create_and_run_pipeline_in_aproject true, 'Two Part Pipeline Template', 'foo_collection_in_aproject', false
187 # Create a pipeline instance from outside of a project
188 test 'Run a pipeline from dashboard' do
189 visit page_with_token('active_trustedclient')
190 create_and_run_pipeline_in_aproject false, 'Two Part Pipeline Template', 'foo_collection_in_aproject', false
193 test 'view pipeline with job and see graph' do
194 visit page_with_token('active_trustedclient', '/pipeline_instances')
195 assert page.has_text? 'pipeline_with_job'
197 find('a', text: 'pipeline_with_job').click
199 # since the pipeline component has a job, expect to see the graph
200 assert page.has_text? 'Graph'
202 page.assert_selector "#provenance_graph"
205 test 'pipeline description' do
206 visit page_with_token('active_trustedclient', '/pipeline_instances')
207 assert page.has_text? 'pipeline_with_job'
209 find('a', text: 'pipeline_with_job').click
211 within('.arv-description-as-subtitle') do
212 find('.fa-pencil').click
213 find('.editable-input textarea').set('*Textile description for pipeline instance*')
214 find('.editable-submit').click
219 assert page.has_no_text? '*Textile description for pipeline instance*'
220 assert page.has_text? 'Textile description for pipeline instance'
223 test "JSON popup available for strange components" do
224 uuid = api_fixture("pipeline_instances")["components_is_jobspec"]["uuid"]
225 visit page_with_token("active", "/pipeline_instances/#{uuid}")
226 click_on "Components"
227 assert(page.has_no_text?("script_parameters"),
228 "components JSON visible without popup")
229 click_on "Show components JSON"
230 assert(page.has_text?("script_parameters"),
231 "components JSON not found")
234 def create_pipeline_from(template_name, project_name="Home")
235 # Visit the named pipeline template and create a pipeline instance from it.
236 # The instance will be created under the named project.
237 template_uuid = api_fixture("pipeline_templates", template_name, "uuid")
238 visit page_with_token("active", "/pipeline_templates/#{template_uuid}")
239 click_on "Run this pipeline"
240 within(".modal-dialog") do # FIXME: source of 3 test errors
241 # Set project for the new pipeline instance
242 find(".selectable", text: project_name).click
245 assert(has_text?("This pipeline was created from the template"),
246 "did not land on pipeline instance page")
249 PROJECT_WITH_SEARCH_COLLECTION = "A Subproject"
250 def check_parameter_search(proj_name)
251 create_pipeline_from("parameter_with_search", proj_name)
252 search_text = api_fixture("pipeline_templates", "parameter_with_search",
253 "components", "with-search",
254 "script_parameters", "input", "search_for")
255 first("a.btn,button", text: "Choose").click
256 within(".modal-body") do
257 if (proj_name != PROJECT_WITH_SEARCH_COLLECTION)
258 # Switch finder modal to Subproject to find the Collection.
260 click_on PROJECT_WITH_SEARCH_COLLECTION
262 assert_equal(search_text, first("input").value,
263 "parameter search not preseeded")
264 assert(has_text?(api_fixture("collections")["baz_collection_name_in_asubproject"]["name"]),
265 "baz Collection not in preseeded search results")
269 test "Workbench respects search_for parameter in templates" do
270 check_parameter_search(PROJECT_WITH_SEARCH_COLLECTION)
273 test "Workbench preserves search_for parameter after project switch" do
274 check_parameter_search("A Project")
277 test "enter a float for a number pipeline input" do
278 # Poltergeist either does not support the HTML 5 <input
279 # type="number">, or interferes with the associated X-Editable
280 # validation code. If the input field has type=number (forcing an
281 # integer), this test will yield a false positive under
282 # Poltergeist. --Brett, 2015-02-05
283 need_selenium "for strict X-Editable input validation"
284 create_pipeline_from("template_with_dataclass_number")
286 ".editable[data-name='[components][work][script_parameters][input][value]']"
287 find(INPUT_SELECTOR).click
288 find(".editable-input input").set("12.34")
289 find("#editable-submit").click
290 assert_no_selector(".editable-popup")
291 assert_selector(INPUT_SELECTOR, text: "12.34")
295 [true, 'Two Part Pipeline Template', 'foo_collection_in_aproject', false],
296 [false, 'Two Part Pipeline Template', 'foo_collection_in_aproject', false],
297 [true, 'Two Part Template with dataclass File', 'foo_collection_in_aproject', true],
298 [false, 'Two Part Template with dataclass File', 'foo_collection_in_aproject', true],
299 [true, 'Two Part Pipeline Template', 'collection_with_no_name_in_aproject', false],
300 ].each do |in_aproject, template_name, collection, choose_file|
301 test "Run pipeline instance in #{in_aproject} with #{template_name} with #{collection} file #{choose_file}" do
303 visit page_with_token 'active', \
304 '/projects/'+api_fixture('groups')['aproject']['uuid']
306 visit page_with_token 'active', '/'
309 # need bigger modal size when choosing a file from collection
310 if Capybara.current_driver == :selenium
311 Capybara.current_session.driver.browser.manage.window.resize_to(1200, 800)
314 create_and_run_pipeline_in_aproject in_aproject, template_name, collection, choose_file
315 instance_path = current_path
318 find('a,button', text: 'Pause').click
319 assert page.has_text? 'Paused'
320 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
321 page.assert_selector 'a,button', text: 'Re-run with latest'
322 page.assert_selector 'a,button', text: 'Re-run options'
324 # Verify that the newly created instance is created in the right project.
325 assert page.has_text? 'Home'
327 assert page.has_text? 'A Project'
329 assert page.has_no_text? 'A Project'
335 ['active', false, false, false],
336 ['active', false, false, true],
337 ['active', true, false, false],
338 ['active', true, true, false],
339 ['active', true, false, true],
340 ['active', true, true, true],
341 ['project_viewer', false, false, true],
342 ['project_viewer', true, true, true],
343 ].each do |user, with_options, choose_options, in_aproject|
344 test "Rerun pipeline instance as #{user} using options #{with_options} #{choose_options} in #{in_aproject}" do
346 path = '/pipeline_instances/'+api_fixture('pipeline_instances')['pipeline_owned_by_active_in_aproject']['uuid']
348 path = '/pipeline_instances/'+api_fixture('pipeline_instances')['pipeline_owned_by_active_in_home']['uuid']
351 visit page_with_token(user, path)
353 page.assert_selector 'a,button', text: 'Re-run with latest'
354 page.assert_selector 'a,button', text: 'Re-run options'
356 if user == 'project_viewer' && in_aproject
357 assert page.has_text? 'A Project'
360 # Now re-run the pipeline
362 assert_triggers_dom_event 'shown.bs.modal' do
363 find('a,button', text: 'Re-run options').click
365 within('.modal-dialog') do
366 page.assert_selector 'a,button', text: 'Copy and edit inputs'
367 page.assert_selector 'a,button', text: 'Run now'
369 find('button', text: 'Copy and edit inputs').click
371 find('button', text: 'Run now').click
375 find('a,button', text: 'Re-run with latest').click
378 # Verify that the newly created instance is created in the right
379 # project. In case of project_viewer user, since the user cannot
380 # write to the project, the pipeline should have been created in
381 # the user's Home project.
382 assert_not_equal path, current_path, 'Rerun instance path expected to be different'
384 if in_aproject && (user != 'project_viewer')
385 assert_text 'A Project'
387 assert_no_text 'A Project'
392 # Create and run a pipeline for 'Two Part Pipeline Template' in 'A Project'
393 def create_and_run_pipeline_in_aproject in_aproject, template_name, collection_fixture, choose_file=false
394 # collection in aproject to be used as input
395 collection = api_fixture('collections', collection_fixture)
397 # create a pipeline instance
398 find('.btn', text: 'Run a process').click
399 within('.modal-dialog') do
400 find('.selectable', text: template_name).click
401 find('.btn', text: 'Next: choose inputs').click
404 assert find('p', text: 'Provide a value')
406 find('div.form-group', text: 'Foo/bar pair').
407 find('.btn', text: 'Choose').
410 within('.modal-dialog') do
412 assert_selector 'button.dropdown-toggle', text: 'A Project'
415 assert_selector 'button.dropdown-toggle', text: 'Home'
418 click_link "A Project"
422 if collection_fixture == 'foo_collection_in_aproject'
423 first('span', text: 'foo_tag').click
424 elsif collection['name']
425 first('span', text: "#{collection['name']}").click
427 collection_uuid = collection['uuid']
428 find("div[data-object-uuid=#{collection_uuid}]").click
433 find('.preview-selectable', text: 'foo').click
435 find('button', text: 'OK').click
438 # The input, after being specified, should still be displayed (#3382)
439 assert find('div.form-group', text: 'Foo/bar pair')
441 # Ensure that the collection's portable_data_hash, uuid and name
442 # are saved in the desired places. (#4015)
443 click_link 'Advanced'
444 click_link 'API response'
446 api_response = JSON.parse(find('div#advanced_api_response pre').text)
447 input_params = api_response['components']['part-one']['script_parameters']['input']
448 assert_equal(input_params['selection_uuid'], collection['uuid'], "Not found expected input param uuid")
450 assert_equal(input_params['value'], collection['portable_data_hash']+'/foo', "Not found expected input file param value")
451 assert_equal(input_params['selection_name'], collection['name']+'/foo', "Not found expected input file param name")
453 assert_equal(input_params['value'], collection['portable_data_hash'], "Not found expected input param value")
454 assert_equal(input_params['selection_name'], collection['name'], "Not found expected input selection name")
457 # "Run" button present and enabled
458 page.assert_no_selector 'a.disabled,button.disabled', text: 'Run'
459 first('a,button', text: 'Run').click
461 # Pipeline is running. We have a "Pause" button instead now.
462 page.assert_no_selector 'a,button', text: 'Run'
463 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
464 page.assert_selector 'a,button', text: 'Pause'
466 # Since it is test env, no jobs are created to run. So, graph not visible
467 assert page.has_no_text? 'Graph'
471 ['user1_with_load', 'zzzzz-d1hrv-10pipelines0001', 0], # run time 0 minutes
472 ['user1_with_load', 'zzzzz-d1hrv-10pipelines0010', 17*60*60 + 51*60], # run time 17 hours and 51 minutes
473 ['active', 'zzzzz-d1hrv-runningpipeline', nil], # state = running
474 ].each do |user, uuid, run_time|
475 test "pipeline start and finish time display for #{uuid}" do
476 need_selenium 'to parse timestamps correctly across DST boundaries'
477 visit page_with_token(user, "/pipeline_instances/#{uuid}")
479 assert page.has_text? 'This pipeline started at'
480 page_text = page.text
483 match = /This pipeline started at (.*)\. It failed after (.*) at (.*)\. Check the Log/.match page_text
485 match = /This pipeline started at (.*). It has been active for(.*)/.match page_text
487 assert_not_nil(match, 'Did not find text - This pipeline started at . . . ')
490 assert_not_nil(start_at, 'Did not find start_at time')
492 start_time = parse_browser_timestamp start_at
494 finished_at = match[3]
495 assert_not_nil(finished_at, 'Did not find finished_at time')
496 finished_time = parse_browser_timestamp finished_at
497 assert_equal(run_time, finished_time-start_time,
498 "Time difference did not match for start_at #{start_at}, finished_at #{finished_at}, ran_for #{match[2]}")
500 match = /\d(.*)/.match match[2]
501 assert_not_nil match, 'Did not find expected match for running component'
507 ['fuse', nil, 2, 20], # has 2 as of 11-07-2014
508 ['user1_with_load', '000025pipelines', 25, 25], # owned_by the project zzzzz-j7d0g-000025pipelines, two pages
509 ['admin', 'pipeline_20', 1, 1],
510 ['active', 'no such match', 0, 0],
511 ].each do |user, search_filter, expected_min, expected_max|
512 test "scroll pipeline instances page for #{user} with search filter #{search_filter}
513 and expect #{expected_min} <= found_items <= #{expected_max}" do
514 visit page_with_token(user, "/pipeline_instances")
517 find('.recent-pipeline-instances-filterable-control').set(search_filter)
518 # Wait for 250ms debounce timer (see filterable.js)
523 page_scrolls = expected_max/20 + 2 # scroll num_pages+2 times to test scrolling is disabled when it should be
524 within('.arv-recent-pipeline-instances') do
525 (0..page_scrolls).each do |i|
526 page.driver.scroll_to 0, 999000
534 # Verify that expected number of pipeline instances are found
535 found_items = page.all('tr[data-kind="arvados#pipelineInstance"]')
536 found_count = found_items.count
537 if expected_min == expected_max
538 assert_equal(true, found_count == expected_min,
539 "Not found expected number of items. Expected #{expected_min} and found #{found_count}")
540 assert page.has_no_text? 'request failed'
542 assert_equal(true, found_count>=expected_min,
543 "Found too few items. Expected at least #{expected_min} and found #{found_count}")
544 assert_equal(true, found_count<=expected_max,
545 "Found too many items. Expected at most #{expected_max} and found #{found_count}")
550 test 'render job run time when job record is inaccessible' do
551 pi = api_fixture('pipeline_instances', 'has_component_with_completed_jobs')
552 visit page_with_token 'active', '/pipeline_instances/' + pi['uuid']
553 assert_text 'Queued for '
556 test "job logs linked for running pipeline" do
557 pi = api_fixture("pipeline_instances", "running_pipeline_with_complete_job")
558 visit(page_with_token("active", "/pipeline_instances/#{pi['uuid']}"))
559 find(:xpath, "//a[@href='#Log']").click
561 assert_text "Log for previous"
562 log_link = find("a", text: "Log for previous")
563 assert_includes(log_link[:href],
564 "/jobs/#{pi["components"]["previous"]["job"]["uuid"]}#Log")
565 assert_selector "#event_log_div"
569 test "job logs linked for complete pipeline" do
570 pi = api_fixture("pipeline_instances", "complete_pipeline_with_two_jobs")
571 visit(page_with_token("active", "/pipeline_instances/#{pi['uuid']}"))
572 find(:xpath, "//a[@href='#Log']").click
574 assert_text "Log for previous"
575 pi["components"].each do |cname, cspec|
576 log_link = find("a", text: "Log for #{cname}")
577 assert_includes(log_link[:href], "/jobs/#{cspec["job"]["uuid"]}#Log")
579 assert_no_selector "#event_log_div"
583 test "job logs linked for failed pipeline" do
584 pi = api_fixture("pipeline_instances", "failed_pipeline_with_two_jobs")
585 visit(page_with_token("active", "/pipeline_instances/#{pi['uuid']}"))
586 find(:xpath, "//a[@href='#Log']").click
588 assert_text "Log for previous"
589 pi["components"].each do |cname, cspec|
590 log_link = find("a", text: "Log for #{cname}")
591 assert_includes(log_link[:href], "/jobs/#{cspec["job"]["uuid"]}#Log")
593 assert_no_selector "#event_log_div"