1 require 'integration_helper'
3 class PipelineInstancesTest < ActionDispatch::IntegrationTest
8 def parse_browser_timestamp t
9 # Timestamps are displayed in the browser's time zone (which can
10 # differ from ours) and they come from toLocaleTimeString (which
11 # means they don't necessarily tell us which time zone they're
12 # using). In order to make sense of them, we need to ask the
13 # browser to parse them and generate a timestamp that can be
16 # Note: Even with all this help, phantomjs seem to behave badly
17 # when parsing timestamps on the other side of a DST transition.
18 # See skipped tests below.
20 # In some locales (e.g., en_CA.UTF-8) Firefox can't parse what its
21 # own toLocaleString() puts out.
22 t.sub!(/(\d\d\d\d)-(\d\d)-(\d\d)/, '\2/\3/\1')
24 if /(\d+:\d+ [AP]M) (\d+\/\d+\/\d+)/ =~ t
25 # Currently dates.js renders timestamps as
26 # '{t.toLocaleTimeString()} {t.toLocaleDateString()}' which even
27 # en_US browsers can't make sense of. First we need to flip it
28 # around so it looks like what toLocaleString() would have made.
29 t = $~[2] + ', ' + $~[1]
32 utc = page.evaluate_script("new Date('#{t}').toUTCString()")
33 DateTime.parse(utc).to_time
37 # No need to test (or mention) these all the time. If they start
38 # working (without need_selenium) then some real tests might not
39 # need_selenium any more.
41 test 'phantomjs DST' do
43 t0s = '3/8/2015, 01:59 AM'
44 t1s = '3/8/2015, 03:01 AM'
45 t0 = parse_browser_timestamp t0s
46 t1 = parse_browser_timestamp t1s
47 assert_equal 120, t1-t0, "'#{t0s}' to '#{t1s}' was reported as #{t1-t0} seconds, should be 120"
50 test 'phantomjs DST 2' do
52 t0s = '2015-03-08T10:43:00Z'
53 t1s = '2015-03-09T03:43:00Z'
54 t0 = parse_browser_timestamp page.evaluate_script("new Date('#{t0s}').toLocaleString()")
55 t1 = parse_browser_timestamp page.evaluate_script("new Date('#{t1s}').toLocaleString()")
56 assert_equal 17*3600, t1-t0, "'#{t0s}' to '#{t1s}' was reported as #{t1-t0} seconds, should be #{17*3600} (17 hours)"
60 test 'Create and run a pipeline' do
61 visit page_with_token('active_trustedclient', '/pipeline_templates')
62 within('tr', text: 'Two Part Pipeline Template') do
63 find('a,button', text: 'Run').click
67 within('.modal-dialog') do #FIXME: source of 1 test error
68 find('.selectable', text: 'A Project').click
69 find('button', text: 'Choose').click
72 # This pipeline needs input. So, Run should be disabled
73 page.assert_selector 'a.disabled,button.disabled', text: 'Run'
75 instance_page = current_path
77 # Add this collection to the project
79 find("#projects-menu").click
80 find('.dropdown-menu a,button', text: 'A Project').click
81 find('.btn', text: 'Add data').click
82 find('.dropdown-menu a,button', text: 'Copy data from another project').click
83 within('.modal-dialog') do
85 first('span', text: 'foo_tag').click
86 find('.btn', text: 'Copy').click
88 using_wait_time(Capybara.default_max_wait_time * 3) do
92 click_link 'Pipelines and processes'
93 find('tr[data-kind="arvados#pipelineInstance"]', text: '(none)').
94 find('a', text: 'Show').
97 assert find('p', text: 'Provide a value')
99 find('div.form-group', text: 'Foo/bar pair').
100 find('.btn', text: 'Choose').
103 within('.modal-dialog') do
104 assert(has_text?("Foo/bar pair"),
105 "pipeline input picker missing name of input")
107 first('span', text: 'foo_tag').click
108 find('button', text: 'OK').click
112 # The input, after being specified, should still be displayed (#3382)
113 assert find('div.form-group', text: 'Foo/bar pair')
115 # The input, after being specified, should still be editable (#3382)
116 find('div.form-group', text: 'Foo/bar pair').
117 find('.btn', text: 'Choose').click
119 within('.modal-dialog') do
120 assert(has_text?("Foo/bar pair"),
121 "pipeline input picker missing name of input")
123 first('span', text: 'foo_tag').click
124 find('button', text: 'OK').click
127 # For good measure, check one last time that the input, after being specified twice, is still be displayed (#3382)
128 assert find('div.form-group', text: 'Foo/bar pair')
130 # Ensure that the collection's portable_data_hash, uuid and name
131 # are saved in the desired places. (#4015)
133 # foo_collection_in_aproject is the collection tagged with foo_tag.
134 collection = api_fixture('collections', 'foo_collection_in_aproject')
135 click_link 'Advanced'
136 click_link 'API response'
137 api_response = JSON.parse(find('div#advanced_api_response pre').text)
138 input_params = api_response['components']['part-one']['script_parameters']['input']
139 assert_equal input_params['value'], collection['portable_data_hash']
140 assert_equal input_params['selection_name'], collection['name']
141 assert_equal input_params['selection_uuid'], collection['uuid']
143 # "Run" button is now enabled
144 page.assert_no_selector 'a.disabled,button.disabled', text: 'Run'
146 first('a,button', text: 'Run').click
148 # Pipeline is running. We have a "Pause" button instead now.
149 page.assert_selector 'a,button', text: 'Pause'
150 find('a,button', text: 'Pause').click
152 # Pipeline is stopped. It should now be in paused state and Runnable again.
153 assert page.has_text? 'Paused'
154 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
155 page.assert_selector 'a,button', text: 'Re-run with latest'
156 page.assert_selector 'a,button', text: 'Re-run options'
158 # Since it is test env, no jobs are created to run. So, graph not visible
159 assert page.has_no_text? 'Graph'
162 # Create a pipeline instance from within a project and run
163 test 'Create pipeline inside a project and run' do
164 visit page_with_token('active_trustedclient', '/projects')
166 # Add collection to the project using Add data button
167 find("#projects-menu").click
168 find('.dropdown-menu a,button', text: 'A Project').click
169 find('.btn', text: 'Add data').click
170 find('.dropdown-menu a,button', text: 'Copy data from another project').click
171 within('.modal-dialog') do
173 first('span', text: 'foo_tag').click
174 find('.btn', text: 'Copy').click
176 using_wait_time(Capybara.default_max_wait_time * 3) do
180 create_and_run_pipeline_in_aproject true, 'Two Part Pipeline Template', 'foo_collection_in_aproject', false
183 # Create a pipeline instance from outside of a project
184 test 'Run a pipeline from dashboard' do
185 visit page_with_token('active_trustedclient')
186 create_and_run_pipeline_in_aproject false, 'Two Part Pipeline Template', 'foo_collection_in_aproject', false
189 test 'view pipeline with job and see graph' do
190 visit page_with_token('active_trustedclient', '/pipeline_instances')
191 assert page.has_text? 'pipeline_with_job'
193 find('a', text: 'pipeline_with_job').click
195 # since the pipeline component has a job, expect to see the graph
196 assert page.has_text? 'Graph'
198 page.assert_selector "#provenance_graph"
201 test 'pipeline description' do
202 visit page_with_token('active_trustedclient', '/pipeline_instances')
203 assert page.has_text? 'pipeline_with_job'
205 find('a', text: 'pipeline_with_job').click
207 within('.arv-description-as-subtitle') do
208 find('.fa-pencil').click
209 find('.editable-input textarea').set('*Textile description for pipeline instance*')
210 find('.editable-submit').click
215 assert page.has_no_text? '*Textile description for pipeline instance*'
216 assert page.has_text? 'Textile description for pipeline instance'
219 test "JSON popup available for strange components" do
220 uuid = api_fixture("pipeline_instances")["components_is_jobspec"]["uuid"]
221 visit page_with_token("active", "/pipeline_instances/#{uuid}")
222 click_on "Components"
223 assert(page.has_no_text?("script_parameters"),
224 "components JSON visible without popup")
225 click_on "Show components JSON"
226 assert(page.has_text?("script_parameters"),
227 "components JSON not found")
230 def create_pipeline_from(template_name, project_name="Home")
231 # Visit the named pipeline template and create a pipeline instance from it.
232 # The instance will be created under the named project.
233 template_uuid = api_fixture("pipeline_templates", template_name, "uuid")
234 visit page_with_token("active", "/pipeline_templates/#{template_uuid}")
235 click_on "Run this pipeline"
236 within(".modal-dialog") do # FIXME: source of 3 test errors
237 # Set project for the new pipeline instance
238 find(".selectable", text: project_name).click
241 assert(has_text?("This pipeline was created from the template"),
242 "did not land on pipeline instance page")
245 PROJECT_WITH_SEARCH_COLLECTION = "A Subproject"
246 def check_parameter_search(proj_name)
247 create_pipeline_from("parameter_with_search", proj_name)
248 search_text = api_fixture("pipeline_templates", "parameter_with_search",
249 "components", "with-search",
250 "script_parameters", "input", "search_for")
251 first("a.btn,button", text: "Choose").click
252 within(".modal-body") do
253 if (proj_name != PROJECT_WITH_SEARCH_COLLECTION)
254 # Switch finder modal to Subproject to find the Collection.
256 click_on PROJECT_WITH_SEARCH_COLLECTION
258 assert_equal(search_text, first("input").value,
259 "parameter search not preseeded")
260 assert(has_text?(api_fixture("collections")["baz_collection_name_in_asubproject"]["name"]),
261 "baz Collection not in preseeded search results")
265 test "Workbench respects search_for parameter in templates" do
266 check_parameter_search(PROJECT_WITH_SEARCH_COLLECTION)
269 test "Workbench preserves search_for parameter after project switch" do
270 check_parameter_search("A Project")
273 test "enter a float for a number pipeline input" do
274 # Poltergeist either does not support the HTML 5 <input
275 # type="number">, or interferes with the associated X-Editable
276 # validation code. If the input field has type=number (forcing an
277 # integer), this test will yield a false positive under
278 # Poltergeist. --Brett, 2015-02-05
279 need_selenium "for strict X-Editable input validation"
280 create_pipeline_from("template_with_dataclass_number")
282 ".editable[data-name='[components][work][script_parameters][input][value]']"
283 find(INPUT_SELECTOR).click
284 find(".editable-input input").set("12.34")
285 find("#editable-submit").click
286 assert_no_selector(".editable-popup")
287 assert_selector(INPUT_SELECTOR, text: "12.34")
291 [true, 'Two Part Pipeline Template', 'foo_collection_in_aproject', false],
292 [false, 'Two Part Pipeline Template', 'foo_collection_in_aproject', false],
293 [true, 'Two Part Template with dataclass File', 'foo_collection_in_aproject', true],
294 [false, 'Two Part Template with dataclass File', 'foo_collection_in_aproject', true],
295 [true, 'Two Part Pipeline Template', 'collection_with_no_name_in_aproject', false],
296 ].each do |in_aproject, template_name, collection, choose_file|
297 test "Run pipeline instance in #{in_aproject} with #{template_name} with #{collection} file #{choose_file}" do
299 visit page_with_token 'active', \
300 '/projects/'+api_fixture('groups')['aproject']['uuid']
302 visit page_with_token 'active', '/'
305 # need bigger modal size when choosing a file from collection
306 if Capybara.current_driver == :selenium
307 Capybara.current_session.driver.browser.manage.window.resize_to(1200, 800)
310 create_and_run_pipeline_in_aproject in_aproject, template_name, collection, choose_file
311 instance_path = current_path
314 find('a,button', text: 'Pause').click
315 assert page.has_text? 'Paused'
316 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
317 page.assert_selector 'a,button', text: 'Re-run with latest'
318 page.assert_selector 'a,button', text: 'Re-run options'
320 # Verify that the newly created instance is created in the right project.
321 assert page.has_text? 'Home'
323 assert page.has_text? 'A Project'
325 assert page.has_no_text? 'A Project'
331 ['active', false, false, false],
332 ['active', false, false, true],
333 ['active', true, false, false],
334 ['active', true, true, false],
335 ['active', true, false, true],
336 ['active', true, true, true],
337 ['project_viewer', false, false, true],
338 ['project_viewer', true, true, true],
339 ].each do |user, with_options, choose_options, in_aproject|
340 test "Rerun pipeline instance as #{user} using options #{with_options} #{choose_options} in #{in_aproject}" do
342 path = '/pipeline_instances/'+api_fixture('pipeline_instances')['pipeline_owned_by_active_in_aproject']['uuid']
344 path = '/pipeline_instances/'+api_fixture('pipeline_instances')['pipeline_owned_by_active_in_home']['uuid']
347 visit page_with_token(user, path)
349 page.assert_selector 'a,button', text: 'Re-run with latest'
350 page.assert_selector 'a,button', text: 'Re-run options'
352 if user == 'project_viewer' && in_aproject
353 assert page.has_text? 'A Project'
356 # Now re-run the pipeline
358 assert_triggers_dom_event 'shown.bs.modal' do
359 find('a,button', text: 'Re-run options').click
361 within('.modal-dialog') do
362 page.assert_selector 'a,button', text: 'Copy and edit inputs'
363 page.assert_selector 'a,button', text: 'Run now'
365 find('button', text: 'Copy and edit inputs').click
367 find('button', text: 'Run now').click
371 find('a,button', text: 'Re-run with latest').click
374 # Verify that the newly created instance is created in the right
375 # project. In case of project_viewer user, since the user cannot
376 # write to the project, the pipeline should have been created in
377 # the user's Home project.
378 assert_not_equal path, current_path, 'Rerun instance path expected to be different'
380 if in_aproject && (user != 'project_viewer')
381 assert_text 'A Project'
383 assert_no_text 'A Project'
388 # Create and run a pipeline for 'Two Part Pipeline Template' in 'A Project'
389 def create_and_run_pipeline_in_aproject in_aproject, template_name, collection_fixture, choose_file=false
390 # collection in aproject to be used as input
391 collection = api_fixture('collections', collection_fixture)
393 # create a pipeline instance
394 find('.btn', text: 'Run a pipeline').click
395 within('.modal-dialog') do
396 find('.selectable', text: template_name).click
397 find('.btn', text: 'Next: choose inputs').click
400 assert find('p', text: 'Provide a value')
402 find('div.form-group', text: 'Foo/bar pair').
403 find('.btn', text: 'Choose').
406 within('.modal-dialog') do
408 assert_selector 'button.dropdown-toggle', text: 'A Project'
411 assert_selector 'button.dropdown-toggle', text: 'Home'
414 click_link "A Project"
418 if collection_fixture == 'foo_collection_in_aproject'
419 first('span', text: 'foo_tag').click
420 elsif collection['name']
421 first('span', text: "#{collection['name']}").click
423 collection_uuid = collection['uuid']
424 find("div[data-object-uuid=#{collection_uuid}]").click
429 find('.preview-selectable', text: 'foo').click
431 find('button', text: 'OK').click
434 # The input, after being specified, should still be displayed (#3382)
435 assert find('div.form-group', text: 'Foo/bar pair')
437 # Ensure that the collection's portable_data_hash, uuid and name
438 # are saved in the desired places. (#4015)
439 click_link 'Advanced'
440 click_link 'API response'
442 api_response = JSON.parse(find('div#advanced_api_response pre').text)
443 input_params = api_response['components']['part-one']['script_parameters']['input']
444 assert_equal(input_params['selection_uuid'], collection['uuid'], "Not found expected input param uuid")
446 assert_equal(input_params['value'], collection['portable_data_hash']+'/foo', "Not found expected input file param value")
447 assert_equal(input_params['selection_name'], collection['name']+'/foo', "Not found expected input file param name")
449 assert_equal(input_params['value'], collection['portable_data_hash'], "Not found expected input param value")
450 assert_equal(input_params['selection_name'], collection['name'], "Not found expected input selection name")
453 # "Run" button present and enabled
454 page.assert_no_selector 'a.disabled,button.disabled', text: 'Run'
455 first('a,button', text: 'Run').click
457 # Pipeline is running. We have a "Pause" button instead now.
458 page.assert_no_selector 'a,button', text: 'Run'
459 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
460 page.assert_selector 'a,button', text: 'Pause'
462 # Since it is test env, no jobs are created to run. So, graph not visible
463 assert page.has_no_text? 'Graph'
467 ['user1_with_load', 'zzzzz-d1hrv-10pipelines0001', 0], # run time 0 minutes
468 ['user1_with_load', 'zzzzz-d1hrv-10pipelines0010', 17*60*60 + 51*60], # run time 17 hours and 51 minutes
469 ['active', 'zzzzz-d1hrv-runningpipeline', nil], # state = running
470 ].each do |user, uuid, run_time|
471 test "pipeline start and finish time display for #{uuid}" do
472 need_selenium 'to parse timestamps correctly across DST boundaries'
473 visit page_with_token(user, "/pipeline_instances/#{uuid}")
475 assert page.has_text? 'This pipeline started at'
476 page_text = page.text
479 match = /This pipeline started at (.*)\. It failed after (.*) at (.*)\. Check the Log/.match page_text
481 match = /This pipeline started at (.*). It has been active for(.*)/.match page_text
483 assert_not_nil(match, 'Did not find text - This pipeline started at . . . ')
486 assert_not_nil(start_at, 'Did not find start_at time')
488 start_time = parse_browser_timestamp start_at
490 finished_at = match[3]
491 assert_not_nil(finished_at, 'Did not find finished_at time')
492 finished_time = parse_browser_timestamp finished_at
493 assert_equal(run_time, finished_time-start_time,
494 "Time difference did not match for start_at #{start_at}, finished_at #{finished_at}, ran_for #{match[2]}")
496 match = /\d(.*)/.match match[2]
497 assert_not_nil match, 'Did not find expected match for running component'
503 ['fuse', nil, 2, 20], # has 2 as of 11-07-2014
504 ['user1_with_load', '000025pipelines', 25, 25], # owned_by the project zzzzz-j7d0g-000025pipelines, two pages
505 ['admin', 'pipeline_20', 1, 1],
506 ['active', 'no such match', 0, 0],
507 ].each do |user, search_filter, expected_min, expected_max|
508 test "scroll pipeline instances page for #{user} with search filter #{search_filter}
509 and expect #{expected_min} <= found_items <= #{expected_max}" do
510 visit page_with_token(user, "/pipeline_instances")
513 find('.recent-pipeline-instances-filterable-control').set(search_filter)
514 # Wait for 250ms debounce timer (see filterable.js)
519 page_scrolls = expected_max/20 + 2 # scroll num_pages+2 times to test scrolling is disabled when it should be
520 within('.arv-recent-pipeline-instances') do
521 (0..page_scrolls).each do |i|
522 page.driver.scroll_to 0, 999000
530 # Verify that expected number of pipeline instances are found
531 found_items = page.all('tr[data-kind="arvados#pipelineInstance"]')
532 found_count = found_items.count
533 if expected_min == expected_max
534 assert_equal(true, found_count == expected_min,
535 "Not found expected number of items. Expected #{expected_min} and found #{found_count}")
536 assert page.has_no_text? 'request failed'
538 assert_equal(true, found_count>=expected_min,
539 "Found too few items. Expected at least #{expected_min} and found #{found_count}")
540 assert_equal(true, found_count<=expected_max,
541 "Found too many items. Expected at most #{expected_max} and found #{found_count}")
546 test 'render job run time when job record is inaccessible' do
547 pi = api_fixture('pipeline_instances', 'has_component_with_completed_jobs')
548 visit page_with_token 'active', '/pipeline_instances/' + pi['uuid']
549 assert_text 'Queued for '
552 test "job logs linked for running pipeline" do
553 pi = api_fixture("pipeline_instances", "running_pipeline_with_complete_job")
554 visit(page_with_token("active", "/pipeline_instances/#{pi['uuid']}"))
555 find(:xpath, "//a[@href='#Log']").click
557 assert_text "Log for previous"
558 log_link = find("a", text: "Log for previous")
559 assert_includes(log_link[:href],
560 "/jobs/#{pi["components"]["previous"]["job"]["uuid"]}#Log")
561 assert_selector "#event_log_div"
565 test "job logs linked for complete pipeline" do
566 pi = api_fixture("pipeline_instances", "complete_pipeline_with_two_jobs")
567 visit(page_with_token("active", "/pipeline_instances/#{pi['uuid']}"))
568 find(:xpath, "//a[@href='#Log']").click
570 assert_text "Log for previous"
571 pi["components"].each do |cname, cspec|
572 log_link = find("a", text: "Log for #{cname}")
573 assert_includes(log_link[:href], "/jobs/#{cspec["job"]["uuid"]}#Log")
575 assert_no_selector "#event_log_div"
579 test "job logs linked for failed pipeline" do
580 pi = api_fixture("pipeline_instances", "failed_pipeline_with_two_jobs")
581 visit(page_with_token("active", "/pipeline_instances/#{pi['uuid']}"))
582 find(:xpath, "//a[@href='#Log']").click
584 assert_text "Log for previous"
585 pi["components"].each do |cname, cspec|
586 log_link = find("a", text: "Log for #{cname}")
587 assert_includes(log_link[:href], "/jobs/#{cspec["job"]["uuid"]}#Log")
589 assert_no_selector "#event_log_div"