1 require 'integration_helper'
2 require 'selenium-webdriver'
5 class PipelineInstancesTest < ActionDispatch::IntegrationTest
7 # Selecting collections requiresLocalStorage
8 headless = Headless.new
10 Capybara.current_driver = :selenium
13 test 'Create and run a pipeline' do
14 visit page_with_token('active_trustedclient')
16 visit '/pipeline_templates'
17 within('tr', text: 'Two Part Pipeline Template') do
18 find('a,button', text: 'Run').click
22 within('.modal-dialog') do
23 find('.selectable', text: 'A Project').click
24 find('button', text: 'Choose').click
27 # This pipeline needs input. So, Run should be disabled
28 page.assert_selector 'a.disabled,button.disabled', text: 'Run'
30 instance_page = current_path
32 # Add this collection to the project
34 find("#projects-menu").click
35 find('.dropdown-menu a,button', text: 'A Project').click
36 find('.btn', text: 'Add data').click
37 find('.dropdown-menu a,button', text: 'Copy data from another project').click
38 within('.modal-dialog') do
40 first('span', text: 'foo_tag').click
41 find('.btn', text: 'Copy').click
43 using_wait_time(Capybara.default_wait_time * 3) do
47 click_link 'Jobs and pipelines'
48 find('tr[data-kind="arvados#pipelineInstance"]', text: '(none)').
49 find('a', text: 'Show').
52 assert find('p', text: 'Provide a value')
54 find('div.form-group', text: 'Foo/bar pair').
55 find('.btn', text: 'Choose').
58 within('.modal-dialog') do
59 assert(has_text?("Foo/bar pair"),
60 "pipeline input picker missing name of input")
62 first('span', text: 'foo_tag').click
63 find('button', text: 'OK').click
67 # The input, after being specified, should still be displayed (#3382)
68 assert find('div.form-group', text: 'Foo/bar pair')
70 # The input, after being specified, should still be editable (#3382)
71 find('div.form-group', text: 'Foo/bar pair').
72 find('.btn', text: 'Choose').
75 within('.modal-dialog') do
76 assert(has_text?("Foo/bar pair"),
77 "pipeline input picker missing name of input")
79 first('span', text: 'foo_tag').click
80 find('button', text: 'OK').click
84 # For good measure, check one last time that the input, after being specified twice, is still be displayed (#3382)
85 assert find('div.form-group', text: 'Foo/bar pair')
87 # Ensure that the collection's portable_data_hash, uuid and name
88 # are saved in the desired places. (#4015)
90 # foo_collection_in_aproject is the collection tagged with foo_tag.
91 collection = api_fixture('collections', 'foo_collection_in_aproject')
93 click_link 'API response'
94 api_response = JSON.parse(find('div#advanced_api_response pre').text)
95 input_params = api_response['components']['part-one']['script_parameters']['input']
96 assert_equal input_params['value'], collection['portable_data_hash']
97 assert_equal input_params['selection_name'], collection['name']
98 assert_equal input_params['selection_uuid'], collection['uuid']
100 # "Run" button is now enabled
101 page.assert_no_selector 'a.disabled,button.disabled', text: 'Run'
103 first('a,button', text: 'Run').click
105 # Pipeline is running. We have a "Pause" button instead now.
106 page.assert_selector 'a,button', text: 'Pause'
107 find('a,button', text: 'Pause').click
109 # Pipeline is stopped. It should now be in paused state and Runnable again.
110 assert page.has_text? 'Paused'
111 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
112 page.assert_selector 'a,button', text: 'Re-run with latest'
113 page.assert_selector 'a,button', text: 'Re-run options'
115 # Since it is test env, no jobs are created to run. So, graph not visible
116 assert_not page.has_text? 'Graph'
119 # Create a pipeline instance from within a project and run
120 test 'Create pipeline inside a project and run' do
121 visit page_with_token('active_trustedclient')
123 # Add this collection to the project using collections menu from top nav
125 find("#projects-menu").click
126 find('.dropdown-menu a,button', text: 'A Project').click
127 find('.btn', text: 'Add data').click
128 find('.dropdown-menu a,button', text: 'Copy data from another project').click
129 within('.modal-dialog') do
131 first('span', text: 'foo_tag').click
132 find('.btn', text: 'Copy').click
134 using_wait_time(Capybara.default_wait_time * 3) do
138 create_and_run_pipeline_in_aproject true, 'Two Part Pipeline Template', 'foo_collection_in_aproject', false
141 # Create a pipeline instance from outside of a project
142 test 'Run a pipeline from dashboard' do
143 visit page_with_token('active_trustedclient')
144 create_and_run_pipeline_in_aproject false, 'Two Part Pipeline Template', 'foo_collection_in_aproject', false
147 test 'view pipeline with job and see graph' do
148 visit page_with_token('active_trustedclient')
150 visit '/pipeline_instances'
151 assert page.has_text? 'pipeline_with_job'
153 find('a', text: 'pipeline_with_job').click
155 # since the pipeline component has a job, expect to see the graph
156 assert page.has_text? 'Graph'
158 page.assert_selector "#provenance_graph"
161 test 'pipeline description' do
162 visit page_with_token('active_trustedclient')
164 visit '/pipeline_instances'
165 assert page.has_text? 'pipeline_with_job'
167 find('a', text: 'pipeline_with_job').click
169 within('.arv-description-as-subtitle') do
170 find('.fa-pencil').click
171 find('.editable-input textarea').set('*Textile description for pipeline instance*')
172 find('.editable-submit').click
177 assert page.has_no_text? '*Textile description for pipeline instance*'
178 assert page.has_text? 'Textile description for pipeline instance'
181 test "JSON popup available for strange components" do
182 uuid = api_fixture("pipeline_instances")["components_is_jobspec"]["uuid"]
183 visit page_with_token("active", "/pipeline_instances/#{uuid}")
184 click_on "Components"
185 assert(page.has_no_text?("script_parameters"),
186 "components JSON visible without popup")
187 click_on "Show components JSON"
188 assert(page.has_text?("script_parameters"),
189 "components JSON not found")
192 PROJECT_WITH_SEARCH_COLLECTION = "A Subproject"
193 def check_parameter_search(proj_name)
194 template = api_fixture("pipeline_templates")["parameter_with_search"]
195 search_text = template["components"]["with-search"]["script_parameters"]["input"]["search_for"]
196 visit page_with_token("active", "/pipeline_templates/#{template['uuid']}")
197 click_on "Run this pipeline"
198 within(".modal-dialog") do # Set project for the new pipeline instance
199 find(".selectable", text: proj_name).click
202 assert(has_text?("This pipeline was created from the template"), "did not land on pipeline instance page")
203 first("a.btn,button", text: "Choose").click
204 within(".modal-body") do
205 if (proj_name != PROJECT_WITH_SEARCH_COLLECTION)
206 # Switch finder modal to Subproject to find the Collection.
208 click_on PROJECT_WITH_SEARCH_COLLECTION
210 assert_equal(search_text, first("input").value,
211 "parameter search not preseeded")
212 assert(has_text?(api_fixture("collections")["baz_collection_name_in_asubproject"]["name"]),
213 "baz Collection not in preseeded search results")
217 test "Workbench respects search_for parameter in templates" do
218 check_parameter_search(PROJECT_WITH_SEARCH_COLLECTION)
221 test "Workbench preserves search_for parameter after project switch" do
222 check_parameter_search("A Project")
226 [true, 'Two Part Pipeline Template', 'foo_collection_in_aproject', false],
227 [false, 'Two Part Pipeline Template', 'foo_collection_in_aproject', false],
228 [true, 'Two Part Template with dataclass File', 'foo_collection_in_aproject', true],
229 [false, 'Two Part Template with dataclass File', 'foo_collection_in_aproject', true],
230 [true, 'Two Part Pipeline Template', 'collection_with_no_name_in_aproject', false],
231 ].each do |in_aproject, template_name, collection, choose_file|
232 test "Run pipeline instance in #{in_aproject} with #{template_name} with #{collection} file #{choose_file}" do
233 visit page_with_token('active')
235 # need bigger modal size when choosing a file from collection
236 Capybara.current_session.driver.browser.manage.window.resize_to(1024, 768)
239 find("#projects-menu").click
240 find('.dropdown-menu a,button', text: 'A Project').click
243 create_and_run_pipeline_in_aproject in_aproject, template_name, collection, choose_file
244 instance_path = current_path
247 find('a,button', text: 'Pause').click
248 assert page.has_text? 'Paused'
249 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
250 page.assert_selector 'a,button', text: 'Re-run with latest'
251 page.assert_selector 'a,button', text: 'Re-run options'
253 # Verify that the newly created instance is created in the right project.
254 assert page.has_text? 'Home'
256 assert page.has_text? 'A Project'
258 assert page.has_no_text? 'A Project'
264 ['active', false, false, false],
265 ['active', false, false, true],
266 ['active', true, false, false],
267 ['active', true, true, false],
268 ['active', true, false, true],
269 ['active', true, true, true],
270 ['project_viewer', false, false, true],
271 ['project_viewer', true, true, true],
272 ].each do |user, with_options, choose_options, in_aproject|
273 test "Rerun pipeline instance as #{user} using options #{with_options} #{choose_options} in #{in_aproject}" do
274 visit page_with_token('active')
276 # need bigger modal size when choosing a file from collection
277 Capybara.current_session.driver.browser.manage.window.resize_to(1024, 768)
280 find("#projects-menu").click
281 find('.dropdown-menu a,button', text: 'A Project').click
284 create_and_run_pipeline_in_aproject in_aproject, 'Two Part Pipeline Template', 'foo_collection_in_aproject'
285 instance_path = current_path
288 find('a,button', text: 'Pause').click
289 assert page.has_text? 'Paused'
290 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
291 page.assert_selector 'a,button', text: 'Re-run with latest'
292 page.assert_selector 'a,button', text: 'Re-run options'
294 # Pipeline can be re-run now. Access it as the specified user, and re-run
295 if user == 'project_viewer'
296 visit page_with_token(user, instance_path)
297 assert page.has_text? 'A Project'
298 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
299 page.assert_selector 'a,button', text: 'Re-run with latest'
300 page.assert_selector 'a,button', text: 'Re-run options'
303 # Now re-run the pipeline
305 find('a,button', text: 'Re-run options').click
306 within('.modal-dialog') do
307 page.assert_selector 'a,button', text: 'Copy and edit inputs'
308 page.assert_selector 'a,button', text: 'Run now'
310 find('button', text: 'Copy and edit inputs').click
312 find('button', text: 'Run now').click
316 find('a,button', text: 'Re-run with latest').click
319 # Verify that the newly created instance is created in the right project.
320 # In case of project_viewer user, since the use cannot write to the project,
321 # the pipeline should have been created in the user's Home project.
322 assert_not_equal instance_path, current_path, 'Rerun instance path expected to be different'
323 assert page.has_text? 'Home'
324 if in_aproject && (user != 'project_viewer')
325 assert page.has_text? 'A Project'
327 assert page.has_no_text? 'A Project'
332 # Create and run a pipeline for 'Two Part Pipeline Template' in 'A Project'
333 def create_and_run_pipeline_in_aproject in_aproject, template_name, collection_fixture, choose_file=false
334 # collection in aproject to be used as input
335 collection = api_fixture('collections', collection_fixture)
337 # create a pipeline instance
338 find('.btn', text: 'Run a pipeline').click
339 within('.modal-dialog') do
340 find('.selectable', text: template_name).click
341 find('.btn', text: 'Next: choose inputs').click
344 assert find('p', text: 'Provide a value')
346 find('div.form-group', text: 'Foo/bar pair').
347 find('.btn', text: 'Choose').
350 within('.modal-dialog') do
352 assert_selector 'button.dropdown-toggle', text: 'A Project'
355 assert_selector 'button.dropdown-toggle', text: 'Home'
358 click_link "A Project"
362 if collection_fixture == 'foo_collection_in_aproject'
363 first('span', text: 'foo_tag').click
364 elsif collection['name']
365 first('span', text: "#{collection['name']}").click
367 collection_uuid = collection['uuid']
368 find("div[data-object-uuid=#{collection_uuid}]").click
373 find('.preview-selectable', text: 'foo').click
375 find('button', text: 'OK').click
379 # The input, after being specified, should still be displayed (#3382)
380 assert find('div.form-group', text: 'Foo/bar pair')
382 # Ensure that the collection's portable_data_hash, uuid and name
383 # are saved in the desired places. (#4015)
384 click_link 'Advanced'
385 click_link 'API response'
386 api_response = JSON.parse(find('div#advanced_api_response pre').text)
387 input_params = api_response['components']['part-one']['script_parameters']['input']
388 assert_equal(input_params['selection_uuid'], collection['uuid'], "Not found expected input param uuid")
390 assert_equal(input_params['value'], collection['portable_data_hash']+'/foo', "Not found expected input file param value")
391 assert_equal(input_params['selection_name'], collection['name']+'/foo', "Not found expected input file param name")
393 assert_equal(input_params['value'], collection['portable_data_hash'], "Not found expected input param value")
394 assert_equal(input_params['selection_name'], collection['name'], "Not found expected input selection name")
397 # "Run" button present and enabled
398 page.assert_no_selector 'a.disabled,button.disabled', text: 'Run'
399 first('a,button', text: 'Run').click
401 # Pipeline is running. We have a "Pause" button instead now.
402 page.assert_no_selector 'a,button', text: 'Run'
403 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
404 page.assert_selector 'a,button', text: 'Pause'
406 # Since it is test env, no jobs are created to run. So, graph not visible
407 assert_not page.has_text? 'Graph'
411 [1, 0], # run time 0 minutes
412 [10, 17*60*60 + 51*60], # run time 17 hours and 51 minutes
413 ].each do |index, run_time|
414 test "pipeline start and finish time display #{index}" do
415 visit page_with_token("user1_with_load", "/pipeline_instances/zzzzz-d1hrv-10pipelines0#{index.to_s.rjust(3, '0')}")
417 assert page.has_text? 'This pipeline started at'
418 page_text = page.text
420 match = /This pipeline started at (.*)\. It failed after (.*) seconds at (.*)\. Check the Log/.match page_text
421 assert_not_nil(match, 'Did not find text - This pipeline started at . . . ')
424 finished_at = match[3]
425 assert_not_nil(start_at, 'Did not find start_at time')
426 assert_not_nil(finished_at, 'Did not find finished_at time')
428 # start and finished time display is of the format '2:20 PM 10/20/2014'
429 start_time = DateTime.strptime(start_at, '%H:%M %p %m/%d/%Y').to_time
430 finished_time = DateTime.strptime(finished_at, '%H:%M %p %m/%d/%Y').to_time
431 assert_equal(run_time, finished_time-start_time,
432 "Time difference did not match for start_at #{start_at}, finished_at #{finished_at}, ran_for #{match[2]}")
437 ['fuse', nil, 2, 20], # has 2 as of 11-07-2014
438 ['fuse', 'FUSE project', 1, 1], # 1 with this name
439 ['user1_with_load', nil, 30, 100], # has 37 as of 11-07-2014
440 ['user1_with_load', 'pipeline_10', 2, 2], # 2 with this name
441 ['user1_with_load', '000010pipelines', 10, 10], # owned_by the project zzzzz-j7d0g-000010pipelines
442 ['user1_with_load', '000025pipelines', 25, 25], # owned_by the project zzzzz-j7d0g-000025pipelines, two pages
443 ['admin', nil, 40, 200],
444 ['admin', 'FUSE project', 1, 1],
445 ['admin', 'pipeline_10', 2, 2],
446 ['active', 'containing at least two', 0, 0], # component description is not a searchable column
447 ['active', nil, 10, 100],
448 ['active', 'no such match', 0, 0],
449 ].each do |user, search_filter, expected_min, expected_max|
450 test "scroll pipeline instances page for #{user} with search filter #{search_filter}
451 and expect #{expected_min} <= found_items <= #{expected_max}" do
452 visit page_with_token(user, "/pipeline_instances")
455 find('.recent-pipeline-instances-filterable-control').set(search_filter)
456 # Wait for 250ms debounce timer (see filterable.js)
461 page_scrolls = expected_max/20 + 2 # scroll num_pages+2 times to test scrolling is disabled when it should be
462 within('.arv-recent-pipeline-instances') do
463 (0..page_scrolls).each do |i|
464 page.execute_script "window.scrollBy(0,999000)"
472 # Verify that expected number of pipeline instances are found
473 found_items = page.all('tr[data-kind="arvados#pipelineInstance"]')
474 found_count = found_items.count
475 if expected_min == expected_max
476 assert_equal(true, found_count == expected_min,
477 "Not found expected number of items. Expected #{expected_min} and found #{found_count}")
478 assert page.has_no_text? 'request failed'
480 assert_equal(true, found_count>=expected_min,
481 "Found too few items. Expected at least #{expected_min} and found #{found_count}")
482 assert_equal(true, found_count<=expected_max,
483 "Found too many items. Expected at most #{expected_max} and found #{found_count}")