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.
19 if /(\d+:\d+ [AP]M) (\d+\/\d+\/\d+)/ =~ t
20 # Currently dates.js renders timestamps as
21 # '{t.toLocaleTimeString()} {t.toLocaleDateString()}' which even
22 # browsers can't make sense of. First we need to flip it around
23 # so it looks like what toLocaleString() would have made.
24 t = $~[2] + ', ' + $~[1]
26 DateTime.parse(page.evaluate_script "new Date('#{t}').toUTCString()").to_time
30 # No need to test (or mention) these all the time. If they start
31 # working (without need_selenium) then some real tests might not
32 # need_selenium any more.
34 test 'phantomjs DST' do
36 t0s = '3/8/2015, 01:59 AM'
37 t1s = '3/8/2015, 03:01 AM'
38 t0 = parse_browser_timestamp t0s
39 t1 = parse_browser_timestamp t1s
40 assert_equal 120, t1-t0, "'#{t0s}' to '#{t1s}' was reported as #{t1-t0} seconds, should be 120"
43 test 'phantomjs DST 2' do
45 t0s = '2015-03-08T10:43:00Z'
46 t1s = '2015-03-09T03:43:00Z'
47 t0 = parse_browser_timestamp page.evaluate_script("new Date('#{t0s}').toLocaleString()")
48 t1 = parse_browser_timestamp page.evaluate_script("new Date('#{t1s}').toLocaleString()")
49 assert_equal 17*3600, t1-t0, "'#{t0s}' to '#{t1s}' was reported as #{t1-t0} seconds, should be #{17*3600} (17 hours)"
53 test 'Create and run a pipeline' do
54 visit page_with_token('active_trustedclient', '/pipeline_templates')
55 within('tr', text: 'Two Part Pipeline Template') do
56 find('a,button', text: 'Run').click
60 within('.modal-dialog') do
61 find('.selectable', text: 'A Project').click
62 find('button', text: 'Choose').click
65 # This pipeline needs input. So, Run should be disabled
66 page.assert_selector 'a.disabled,button.disabled', text: 'Run'
68 instance_page = current_path
70 # Add this collection to the project
72 find("#projects-menu").click
73 find('.dropdown-menu a,button', text: 'A Project').click
74 find('.btn', text: 'Add data').click
75 find('.dropdown-menu a,button', text: 'Copy data from another project').click
76 within('.modal-dialog') do
78 first('span', text: 'foo_tag').click
79 find('.btn', text: 'Copy').click
81 using_wait_time(Capybara.default_max_wait_time * 3) do
85 click_link 'Jobs and pipelines'
86 find('tr[data-kind="arvados#pipelineInstance"]', text: '(none)').
87 find('a', text: 'Show').
90 assert find('p', text: 'Provide a value')
92 find('div.form-group', text: 'Foo/bar pair').
93 find('.btn', text: 'Choose').
96 within('.modal-dialog') do
97 assert(has_text?("Foo/bar pair"),
98 "pipeline input picker missing name of input")
100 first('span', text: 'foo_tag').click
101 find('button', text: 'OK').click
105 # The input, after being specified, should still be displayed (#3382)
106 assert find('div.form-group', text: 'Foo/bar pair')
108 # The input, after being specified, should still be editable (#3382)
109 find('div.form-group', text: 'Foo/bar pair').
110 find('.btn', text: 'Choose').click
112 within('.modal-dialog') do
113 assert(has_text?("Foo/bar pair"),
114 "pipeline input picker missing name of input")
116 first('span', text: 'foo_tag').click
117 find('button', text: 'OK').click
120 # For good measure, check one last time that the input, after being specified twice, is still be displayed (#3382)
121 assert find('div.form-group', text: 'Foo/bar pair')
123 # Ensure that the collection's portable_data_hash, uuid and name
124 # are saved in the desired places. (#4015)
126 # foo_collection_in_aproject is the collection tagged with foo_tag.
127 collection = api_fixture('collections', 'foo_collection_in_aproject')
128 click_link 'Advanced'
129 click_link 'API response'
130 api_response = JSON.parse(find('div#advanced_api_response pre').text)
131 input_params = api_response['components']['part-one']['script_parameters']['input']
132 assert_equal input_params['value'], collection['portable_data_hash']
133 assert_equal input_params['selection_name'], collection['name']
134 assert_equal input_params['selection_uuid'], collection['uuid']
136 # "Run" button is now enabled
137 page.assert_no_selector 'a.disabled,button.disabled', text: 'Run'
139 first('a,button', text: 'Run').click
141 # Pipeline is running. We have a "Pause" button instead now.
142 page.assert_selector 'a,button', text: 'Pause'
143 find('a,button', text: 'Pause').click
145 # Pipeline is stopped. It should now be in paused state and Runnable again.
146 assert page.has_text? 'Paused'
147 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
148 page.assert_selector 'a,button', text: 'Re-run with latest'
149 page.assert_selector 'a,button', text: 'Re-run options'
151 # Since it is test env, no jobs are created to run. So, graph not visible
152 assert_not page.has_text? 'Graph'
155 # Create a pipeline instance from within a project and run
156 test 'Create pipeline inside a project and run' do
157 visit page_with_token('active_trustedclient', '/projects')
159 # Add collection to the project using Add data button
160 find("#projects-menu").click
161 find('.dropdown-menu a,button', text: 'A Project').click
162 find('.btn', text: 'Add data').click
163 find('.dropdown-menu a,button', text: 'Copy data from another project').click
164 within('.modal-dialog') do
166 first('span', text: 'foo_tag').click
167 find('.btn', text: 'Copy').click
169 using_wait_time(Capybara.default_max_wait_time * 3) do
173 create_and_run_pipeline_in_aproject true, 'Two Part Pipeline Template', 'foo_collection_in_aproject', false
176 # Create a pipeline instance from outside of a project
177 test 'Run a pipeline from dashboard' do
178 visit page_with_token('active_trustedclient')
179 create_and_run_pipeline_in_aproject false, 'Two Part Pipeline Template', 'foo_collection_in_aproject', false
182 test 'view pipeline with job and see graph' do
183 visit page_with_token('active_trustedclient', '/pipeline_instances')
184 assert page.has_text? 'pipeline_with_job'
186 find('a', text: 'pipeline_with_job').click
188 # since the pipeline component has a job, expect to see the graph
189 assert page.has_text? 'Graph'
191 page.assert_selector "#provenance_graph"
194 test 'pipeline description' do
195 visit page_with_token('active_trustedclient', '/pipeline_instances')
196 assert page.has_text? 'pipeline_with_job'
198 find('a', text: 'pipeline_with_job').click
200 within('.arv-description-as-subtitle') do
201 find('.fa-pencil').click
202 find('.editable-input textarea').set('*Textile description for pipeline instance*')
203 find('.editable-submit').click
208 assert page.has_no_text? '*Textile description for pipeline instance*'
209 assert page.has_text? 'Textile description for pipeline instance'
212 test "JSON popup available for strange components" do
213 uuid = api_fixture("pipeline_instances")["components_is_jobspec"]["uuid"]
214 visit page_with_token("active", "/pipeline_instances/#{uuid}")
215 click_on "Components"
216 assert(page.has_no_text?("script_parameters"),
217 "components JSON visible without popup")
218 click_on "Show components JSON"
219 assert(page.has_text?("script_parameters"),
220 "components JSON not found")
223 def create_pipeline_from(template_name, project_name="Home")
224 # Visit the named pipeline template and create a pipeline instance from it.
225 # The instance will be created under the named project.
226 template_uuid = api_fixture("pipeline_templates", template_name, "uuid")
227 visit page_with_token("active", "/pipeline_templates/#{template_uuid}")
228 click_on "Run this pipeline"
229 within(".modal-dialog") do
230 # Set project for the new pipeline instance
231 find(".selectable", text: project_name).click
234 assert(has_text?("This pipeline was created from the template"),
235 "did not land on pipeline instance page")
238 PROJECT_WITH_SEARCH_COLLECTION = "A Subproject"
239 def check_parameter_search(proj_name)
240 create_pipeline_from("parameter_with_search", proj_name)
241 search_text = api_fixture("pipeline_templates", "parameter_with_search",
242 "components", "with-search",
243 "script_parameters", "input", "search_for")
244 first("a.btn,button", text: "Choose").click
245 within(".modal-body") do
246 if (proj_name != PROJECT_WITH_SEARCH_COLLECTION)
247 # Switch finder modal to Subproject to find the Collection.
249 click_on PROJECT_WITH_SEARCH_COLLECTION
251 assert_equal(search_text, first("input").value,
252 "parameter search not preseeded")
253 assert(has_text?(api_fixture("collections")["baz_collection_name_in_asubproject"]["name"]),
254 "baz Collection not in preseeded search results")
258 test "Workbench respects search_for parameter in templates" do
259 check_parameter_search(PROJECT_WITH_SEARCH_COLLECTION)
262 test "Workbench preserves search_for parameter after project switch" do
263 check_parameter_search("A Project")
266 test "enter a float for a number pipeline input" do
267 # Poltergeist either does not support the HTML 5 <input
268 # type="number">, or interferes with the associated X-Editable
269 # validation code. If the input field has type=number (forcing an
270 # integer), this test will yield a false positive under
271 # Poltergeist. --Brett, 2015-02-05
272 need_selenium "for strict X-Editable input validation"
273 create_pipeline_from("template_with_dataclass_number")
275 ".editable[data-name='[components][work][script_parameters][input][value]']"
276 find(INPUT_SELECTOR).click
277 find(".editable-input input").set("12.34")
278 find("#editable-submit").click
279 assert_no_selector(".editable-popup")
280 assert_selector(INPUT_SELECTOR, text: "12.34")
284 [true, 'Two Part Pipeline Template', 'foo_collection_in_aproject', false],
285 [false, 'Two Part Pipeline Template', 'foo_collection_in_aproject', false],
286 [true, 'Two Part Template with dataclass File', 'foo_collection_in_aproject', true],
287 [false, 'Two Part Template with dataclass File', 'foo_collection_in_aproject', true],
288 [true, 'Two Part Pipeline Template', 'collection_with_no_name_in_aproject', false],
289 ].each do |in_aproject, template_name, collection, choose_file|
290 test "Run pipeline instance in #{in_aproject} with #{template_name} with #{collection} file #{choose_file}" do
292 visit page_with_token 'active', \
293 '/projects/'+api_fixture('groups')['aproject']['uuid']
295 visit page_with_token 'active', '/'
298 # need bigger modal size when choosing a file from collection
299 if Capybara.current_driver == :selenium
300 Capybara.current_session.driver.browser.manage.window.resize_to(1200, 800)
303 create_and_run_pipeline_in_aproject in_aproject, template_name, collection, choose_file
304 instance_path = current_path
307 find('a,button', text: 'Pause').click
308 assert page.has_text? 'Paused'
309 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
310 page.assert_selector 'a,button', text: 'Re-run with latest'
311 page.assert_selector 'a,button', text: 'Re-run options'
313 # Verify that the newly created instance is created in the right project.
314 assert page.has_text? 'Home'
316 assert page.has_text? 'A Project'
318 assert page.has_no_text? 'A Project'
324 ['active', false, false, false],
325 ['active', false, false, true],
326 ['active', true, false, false],
327 ['active', true, true, false],
328 ['active', true, false, true],
329 ['active', true, true, true],
330 ['project_viewer', false, false, true],
331 ['project_viewer', true, true, true],
332 ].each do |user, with_options, choose_options, in_aproject|
333 test "Rerun pipeline instance as #{user} using options #{with_options} #{choose_options} in #{in_aproject}" do
335 path = '/pipeline_instances/'+api_fixture('pipeline_instances')['pipeline_owned_by_active_in_aproject']['uuid']
337 path = '/pipeline_instances/'+api_fixture('pipeline_instances')['pipeline_owned_by_active_in_home']['uuid']
340 visit page_with_token(user, path)
342 page.assert_selector 'a,button', text: 'Re-run with latest'
343 page.assert_selector 'a,button', text: 'Re-run options'
345 if user == 'project_viewer' && in_aproject
346 assert page.has_text? 'A Project'
349 # Now re-run the pipeline
351 assert_triggers_dom_event 'shown.bs.modal' do
352 find('a,button', text: 'Re-run options').click
354 within('.modal-dialog') do
355 page.assert_selector 'a,button', text: 'Copy and edit inputs'
356 page.assert_selector 'a,button', text: 'Run now'
358 find('button', text: 'Copy and edit inputs').click
360 find('button', text: 'Run now').click
364 find('a,button', text: 'Re-run with latest').click
367 # Verify that the newly created instance is created in the right
368 # project. In case of project_viewer user, since the user cannot
369 # write to the project, the pipeline should have been created in
370 # the user's Home project.
371 assert_not_equal path, current_path, 'Rerun instance path expected to be different'
373 if in_aproject && (user != 'project_viewer')
374 assert_text 'A Project'
376 assert_no_text 'A Project'
381 # Create and run a pipeline for 'Two Part Pipeline Template' in 'A Project'
382 def create_and_run_pipeline_in_aproject in_aproject, template_name, collection_fixture, choose_file=false
383 # collection in aproject to be used as input
384 collection = api_fixture('collections', collection_fixture)
386 # create a pipeline instance
387 find('.btn', text: 'Run a pipeline').click
388 within('.modal-dialog') do
389 find('.selectable', text: template_name).click
390 find('.btn', text: 'Next: choose inputs').click
393 assert find('p', text: 'Provide a value')
395 find('div.form-group', text: 'Foo/bar pair').
396 find('.btn', text: 'Choose').
399 within('.modal-dialog') do
401 assert_selector 'button.dropdown-toggle', text: 'A Project'
404 assert_selector 'button.dropdown-toggle', text: 'Home'
407 click_link "A Project"
411 if collection_fixture == 'foo_collection_in_aproject'
412 first('span', text: 'foo_tag').click
413 elsif collection['name']
414 first('span', text: "#{collection['name']}").click
416 collection_uuid = collection['uuid']
417 find("div[data-object-uuid=#{collection_uuid}]").click
422 find('.preview-selectable', text: 'foo').click
424 find('button', text: 'OK').click
427 # The input, after being specified, should still be displayed (#3382)
428 assert find('div.form-group', text: 'Foo/bar pair')
430 # Ensure that the collection's portable_data_hash, uuid and name
431 # are saved in the desired places. (#4015)
432 click_link 'Advanced'
433 click_link 'API response'
435 api_response = JSON.parse(find('div#advanced_api_response pre').text)
436 input_params = api_response['components']['part-one']['script_parameters']['input']
437 assert_equal(input_params['selection_uuid'], collection['uuid'], "Not found expected input param uuid")
439 assert_equal(input_params['value'], collection['portable_data_hash']+'/foo', "Not found expected input file param value")
440 assert_equal(input_params['selection_name'], collection['name']+'/foo', "Not found expected input file param name")
442 assert_equal(input_params['value'], collection['portable_data_hash'], "Not found expected input param value")
443 assert_equal(input_params['selection_name'], collection['name'], "Not found expected input selection name")
446 # "Run" button present and enabled
447 page.assert_no_selector 'a.disabled,button.disabled', text: 'Run'
448 first('a,button', text: 'Run').click
450 # Pipeline is running. We have a "Pause" button instead now.
451 page.assert_no_selector 'a,button', text: 'Run'
452 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
453 page.assert_selector 'a,button', text: 'Pause'
455 # Since it is test env, no jobs are created to run. So, graph not visible
456 assert_not page.has_text? 'Graph'
460 ['user1_with_load', 'zzzzz-d1hrv-10pipelines0001', 0], # run time 0 minutes
461 ['user1_with_load', 'zzzzz-d1hrv-10pipelines0010', 17*60*60 + 51*60], # run time 17 hours and 51 minutes
462 ['active', 'zzzzz-d1hrv-runningpipeline', nil], # state = running
463 ].each do |user, uuid, run_time|
464 test "pipeline start and finish time display for #{uuid}" do
465 need_selenium 'to parse timestamps correctly across DST boundaries'
466 visit page_with_token(user, "/pipeline_instances/#{uuid}")
468 assert page.has_text? 'This pipeline started at'
469 page_text = page.text
472 match = /This pipeline started at (.*)\. It failed after (.*) at (.*)\. Check the Log/.match page_text
474 match = /This pipeline started at (.*). It has been active for(.*)/.match page_text
476 assert_not_nil(match, 'Did not find text - This pipeline started at . . . ')
479 assert_not_nil(start_at, 'Did not find start_at time')
481 start_time = parse_browser_timestamp start_at
483 finished_at = match[3]
484 assert_not_nil(finished_at, 'Did not find finished_at time')
485 finished_time = parse_browser_timestamp finished_at
486 assert_equal(run_time, finished_time-start_time,
487 "Time difference did not match for start_at #{start_at}, finished_at #{finished_at}, ran_for #{match[2]}")
489 match = /\d(.*)/.match match[2]
490 assert_not_nil match, 'Did not find expected match for running component'
496 ['fuse', nil, 2, 20], # has 2 as of 11-07-2014
497 ['user1_with_load', '000025pipelines', 25, 25], # owned_by the project zzzzz-j7d0g-000025pipelines, two pages
498 ['admin', 'pipeline_20', 1, 1],
499 ['active', 'no such match', 0, 0],
500 ].each do |user, search_filter, expected_min, expected_max|
501 test "scroll pipeline instances page for #{user} with search filter #{search_filter}
502 and expect #{expected_min} <= found_items <= #{expected_max}" do
503 visit page_with_token(user, "/pipeline_instances")
506 find('.recent-pipeline-instances-filterable-control').set(search_filter)
507 # Wait for 250ms debounce timer (see filterable.js)
512 page_scrolls = expected_max/20 + 2 # scroll num_pages+2 times to test scrolling is disabled when it should be
513 within('.arv-recent-pipeline-instances') do
514 (0..page_scrolls).each do |i|
515 page.driver.scroll_to 0, 999000
523 # Verify that expected number of pipeline instances are found
524 found_items = page.all('tr[data-kind="arvados#pipelineInstance"]')
525 found_count = found_items.count
526 if expected_min == expected_max
527 assert_equal(true, found_count == expected_min,
528 "Not found expected number of items. Expected #{expected_min} and found #{found_count}")
529 assert page.has_no_text? 'request failed'
531 assert_equal(true, found_count>=expected_min,
532 "Found too few items. Expected at least #{expected_min} and found #{found_count}")
533 assert_equal(true, found_count<=expected_max,
534 "Found too many items. Expected at most #{expected_max} and found #{found_count}")
539 test 'render job run time when job record is inaccessible' do
540 pi = api_fixture('pipeline_instances', 'has_component_with_completed_jobs')
541 visit page_with_token 'active', '/pipeline_instances/' + pi['uuid']
542 assert_text 'Queued for '
545 test "job logs linked for running pipeline" do
546 pi = api_fixture("pipeline_instances", "running_pipeline_with_complete_job")
547 visit(page_with_token("active", "/pipeline_instances/#{pi['uuid']}"))
548 find(:xpath, "//a[@href='#Log']").click
550 assert_text "Log for previous"
551 log_link = find("a", text: "Log for previous")
552 assert_includes(log_link[:href],
553 "/jobs/#{pi["components"]["previous"]["job"]["uuid"]}#Log")
554 assert_selector "#event_log_div"
558 test "job logs linked for complete pipeline" do
559 pi = api_fixture("pipeline_instances", "complete_pipeline_with_two_jobs")
560 visit(page_with_token("active", "/pipeline_instances/#{pi['uuid']}"))
561 find(:xpath, "//a[@href='#Log']").click
563 assert_text "Log for previous"
564 pi["components"].each do |cname, cspec|
565 log_link = find("a", text: "Log for #{cname}")
566 assert_includes(log_link[:href], "/jobs/#{cspec["job"]["uuid"]}#Log")
568 assert_no_selector "#event_log_div"
572 test "job logs linked for failed pipeline" do
573 pi = api_fixture("pipeline_instances", "failed_pipeline_with_two_jobs")
574 visit(page_with_token("active", "/pipeline_instances/#{pi['uuid']}"))
575 find(:xpath, "//a[@href='#Log']").click
577 assert_text "Log for previous"
578 pi["components"].each do |cname, cspec|
579 log_link = find("a", text: "Log for #{cname}")
580 assert_includes(log_link[:href], "/jobs/#{cspec["job"]["uuid"]}#Log")
582 assert_no_selector "#event_log_div"