1 require 'integration_helper'
3 class PipelineInstancesTest < ActionDispatch::IntegrationTest
8 test 'Create and run a pipeline' do
9 visit page_with_token('active_trustedclient')
11 visit '/pipeline_templates'
12 within('tr', text: 'Two Part Pipeline Template') do
13 find('a,button', text: 'Run').click
17 within('.modal-dialog') do
18 find('.selectable', text: 'A Project').click
19 find('button', text: 'Choose').click
22 # This pipeline needs input. So, Run should be disabled
23 page.assert_selector 'a.disabled,button.disabled', text: 'Run'
25 instance_page = current_path
27 # Add this collection to the project
29 find("#projects-menu").click
30 find('.dropdown-menu a,button', text: 'A Project').click
31 find('.btn', text: 'Add data').click
32 find('.dropdown-menu a,button', text: 'Copy data from another project').click
33 within('.modal-dialog') do
35 first('span', text: 'foo_tag').click
36 find('.btn', text: 'Copy').click
38 using_wait_time(Capybara.default_wait_time * 3) do
42 click_link 'Jobs and pipelines'
43 find('tr[data-kind="arvados#pipelineInstance"]', text: '(none)').
44 find('a', text: 'Show').
47 assert find('p', text: 'Provide a value')
49 find('div.form-group', text: 'Foo/bar pair').
50 find('.btn', text: 'Choose').
53 within('.modal-dialog') do
54 assert(has_text?("Foo/bar pair"),
55 "pipeline input picker missing name of input")
57 first('span', text: 'foo_tag').click
58 find('button', text: 'OK').click
62 # The input, after being specified, should still be displayed (#3382)
63 assert find('div.form-group', text: 'Foo/bar pair')
65 # The input, after being specified, should still be editable (#3382)
66 find('div.form-group', text: 'Foo/bar pair').
67 find('.btn', text: 'Choose').click
69 within('.modal-dialog') do
70 assert(has_text?("Foo/bar pair"),
71 "pipeline input picker missing name of input")
73 first('span', text: 'foo_tag').click
74 find('button', text: 'OK').click
77 # For good measure, check one last time that the input, after being specified twice, is still be displayed (#3382)
78 assert find('div.form-group', text: 'Foo/bar pair')
80 # Ensure that the collection's portable_data_hash, uuid and name
81 # are saved in the desired places. (#4015)
83 # foo_collection_in_aproject is the collection tagged with foo_tag.
84 collection = api_fixture('collections', 'foo_collection_in_aproject')
86 click_link 'API response'
87 api_response = JSON.parse(find('div#advanced_api_response pre').text)
88 input_params = api_response['components']['part-one']['script_parameters']['input']
89 assert_equal input_params['value'], collection['portable_data_hash']
90 assert_equal input_params['selection_name'], collection['name']
91 assert_equal input_params['selection_uuid'], collection['uuid']
93 # "Run" button is now enabled
94 page.assert_no_selector 'a.disabled,button.disabled', text: 'Run'
96 first('a,button', text: 'Run').click
98 # Pipeline is running. We have a "Pause" button instead now.
99 page.assert_selector 'a,button', text: 'Pause'
100 find('a,button', text: 'Pause').click
102 # Pipeline is stopped. It should now be in paused state and Runnable again.
103 assert page.has_text? 'Paused'
104 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
105 page.assert_selector 'a,button', text: 'Re-run with latest'
106 page.assert_selector 'a,button', text: 'Re-run options'
108 # Since it is test env, no jobs are created to run. So, graph not visible
109 assert_not page.has_text? 'Graph'
112 # Create a pipeline instance from within a project and run
113 test 'Create pipeline inside a project and run' do
114 visit page_with_token('active_trustedclient')
116 # Add this collection to the project using collections menu from top nav
118 find("#projects-menu").click
119 find('.dropdown-menu a,button', text: 'A Project').click
120 find('.btn', text: 'Add data').click
121 find('.dropdown-menu a,button', text: 'Copy data from another project').click
122 within('.modal-dialog') do
124 first('span', text: 'foo_tag').click
125 find('.btn', text: 'Copy').click
127 using_wait_time(Capybara.default_wait_time * 3) do
131 create_and_run_pipeline_in_aproject true, 'Two Part Pipeline Template', 'foo_collection_in_aproject', false
134 # Create a pipeline instance from outside of a project
135 test 'Run a pipeline from dashboard' do
136 visit page_with_token('active_trustedclient')
137 create_and_run_pipeline_in_aproject false, 'Two Part Pipeline Template', 'foo_collection_in_aproject', false
140 test 'view pipeline with job and see graph' do
141 visit page_with_token('active_trustedclient')
143 visit '/pipeline_instances'
144 assert page.has_text? 'pipeline_with_job'
146 find('a', text: 'pipeline_with_job').click
148 # since the pipeline component has a job, expect to see the graph
149 assert page.has_text? 'Graph'
151 page.assert_selector "#provenance_graph"
154 test 'pipeline description' do
155 visit page_with_token('active_trustedclient')
157 visit '/pipeline_instances'
158 assert page.has_text? 'pipeline_with_job'
160 find('a', text: 'pipeline_with_job').click
162 within('.arv-description-as-subtitle') do
163 find('.fa-pencil').click
164 find('.editable-input textarea').set('*Textile description for pipeline instance*')
165 find('.editable-submit').click
170 assert page.has_no_text? '*Textile description for pipeline instance*'
171 assert page.has_text? 'Textile description for pipeline instance'
174 test "JSON popup available for strange components" do
175 uuid = api_fixture("pipeline_instances")["components_is_jobspec"]["uuid"]
176 visit page_with_token("active", "/pipeline_instances/#{uuid}")
177 click_on "Components"
178 assert(page.has_no_text?("script_parameters"),
179 "components JSON visible without popup")
180 click_on "Show components JSON"
181 assert(page.has_text?("script_parameters"),
182 "components JSON not found")
185 PROJECT_WITH_SEARCH_COLLECTION = "A Subproject"
186 def check_parameter_search(proj_name)
187 template = api_fixture("pipeline_templates")["parameter_with_search"]
188 search_text = template["components"]["with-search"]["script_parameters"]["input"]["search_for"]
189 visit page_with_token("active", "/pipeline_templates/#{template['uuid']}")
190 click_on "Run this pipeline"
191 within(".modal-dialog") do # Set project for the new pipeline instance
192 find(".selectable", text: proj_name).click
195 assert(has_text?("This pipeline was created from the template"), "did not land on pipeline instance page")
196 first("a.btn,button", text: "Choose").click
197 within(".modal-body") do
198 if (proj_name != PROJECT_WITH_SEARCH_COLLECTION)
199 # Switch finder modal to Subproject to find the Collection.
201 click_on PROJECT_WITH_SEARCH_COLLECTION
203 assert_equal(search_text, first("input").value,
204 "parameter search not preseeded")
205 assert(has_text?(api_fixture("collections")["baz_collection_name_in_asubproject"]["name"]),
206 "baz Collection not in preseeded search results")
210 test "Workbench respects search_for parameter in templates" do
211 check_parameter_search(PROJECT_WITH_SEARCH_COLLECTION)
214 test "Workbench preserves search_for parameter after project switch" do
215 check_parameter_search("A Project")
219 [true, 'Two Part Pipeline Template', 'foo_collection_in_aproject', false],
220 [false, 'Two Part Pipeline Template', 'foo_collection_in_aproject', false],
221 [true, 'Two Part Template with dataclass File', 'foo_collection_in_aproject', true],
222 [false, 'Two Part Template with dataclass File', 'foo_collection_in_aproject', true],
223 [true, 'Two Part Pipeline Template', 'collection_with_no_name_in_aproject', false],
224 ].each do |in_aproject, template_name, collection, choose_file|
225 test "Run pipeline instance in #{in_aproject} with #{template_name} with #{collection} file #{choose_file}" do
227 visit page_with_token 'active', \
228 '/projects/'+api_fixture('groups')['aproject']['uuid']
230 visit page_with_token 'active', '/'
233 # need bigger modal size when choosing a file from collection
234 if Capybara.current_driver == :selenium
235 Capybara.current_session.driver.browser.manage.window.resize_to(1200, 800)
238 create_and_run_pipeline_in_aproject in_aproject, template_name, collection, choose_file
239 instance_path = current_path
242 find('a,button', text: 'Pause').click
243 assert page.has_text? 'Paused'
244 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
245 page.assert_selector 'a,button', text: 'Re-run with latest'
246 page.assert_selector 'a,button', text: 'Re-run options'
248 # Verify that the newly created instance is created in the right project.
249 assert page.has_text? 'Home'
251 assert page.has_text? 'A Project'
253 assert page.has_no_text? 'A Project'
259 ['active', false, false, false],
260 ['active', false, false, true],
261 ['active', true, false, false],
262 ['active', true, true, false],
263 ['active', true, false, true],
264 ['active', true, true, true],
265 ['project_viewer', false, false, true],
266 ['project_viewer', true, true, true],
267 ].each do |user, with_options, choose_options, in_aproject|
268 test "Rerun pipeline instance as #{user} using options #{with_options} #{choose_options} in #{in_aproject}" do
270 path = '/pipeline_instances/'+api_fixture('pipeline_instances')['pipeline_owned_by_active_in_aproject']['uuid']
272 path = '/pipeline_instances/'+api_fixture('pipeline_instances')['pipeline_owned_by_active_in_home']['uuid']
275 visit page_with_token(user, path)
277 page.assert_selector 'a,button', text: 'Re-run with latest'
278 page.assert_selector 'a,button', text: 'Re-run options'
280 if user == 'project_viewer' && in_aproject
281 assert page.has_text? 'A Project'
284 # Now re-run the pipeline
286 assert_triggers_dom_event 'shown.bs.modal' do
287 find('a,button', text: 'Re-run options').click
289 within('.modal-dialog') do
290 page.assert_selector 'a,button', text: 'Copy and edit inputs'
291 page.assert_selector 'a,button', text: 'Run now'
293 find('button', text: 'Copy and edit inputs').click
295 find('button', text: 'Run now').click
299 find('a,button', text: 'Re-run with latest').click
302 # Verify that the newly created instance is created in the right
303 # project. In case of project_viewer user, since the user cannot
304 # write to the project, the pipeline should have been created in
305 # the user's Home project.
306 assert_not_equal path, current_path, 'Rerun instance path expected to be different'
308 if in_aproject && (user != 'project_viewer')
309 assert_text 'A Project'
311 assert_no_text 'A Project'
316 # Create and run a pipeline for 'Two Part Pipeline Template' in 'A Project'
317 def create_and_run_pipeline_in_aproject in_aproject, template_name, collection_fixture, choose_file=false
318 # collection in aproject to be used as input
319 collection = api_fixture('collections', collection_fixture)
321 # create a pipeline instance
322 find('.btn', text: 'Run a pipeline').click
323 within('.modal-dialog') do
324 find('.selectable', text: template_name).click
325 find('.btn', text: 'Next: choose inputs').click
328 assert find('p', text: 'Provide a value')
330 find('div.form-group', text: 'Foo/bar pair').
331 find('.btn', text: 'Choose').
334 within('.modal-dialog') do
336 assert_selector 'button.dropdown-toggle', text: 'A Project'
339 assert_selector 'button.dropdown-toggle', text: 'Home'
342 click_link "A Project"
346 if collection_fixture == 'foo_collection_in_aproject'
347 first('span', text: 'foo_tag').click
348 elsif collection['name']
349 first('span', text: "#{collection['name']}").click
351 collection_uuid = collection['uuid']
352 find("div[data-object-uuid=#{collection_uuid}]").click
357 find('.preview-selectable', text: 'foo').click
359 find('button', text: 'OK').click
362 # The input, after being specified, should still be displayed (#3382)
363 assert find('div.form-group', text: 'Foo/bar pair')
365 # Ensure that the collection's portable_data_hash, uuid and name
366 # are saved in the desired places. (#4015)
367 click_link 'Advanced'
368 click_link 'API response'
370 api_response = JSON.parse(find('div#advanced_api_response pre').text)
371 input_params = api_response['components']['part-one']['script_parameters']['input']
372 assert_equal(input_params['selection_uuid'], collection['uuid'], "Not found expected input param uuid")
374 assert_equal(input_params['value'], collection['portable_data_hash']+'/foo', "Not found expected input file param value")
375 assert_equal(input_params['selection_name'], collection['name']+'/foo', "Not found expected input file param name")
377 assert_equal(input_params['value'], collection['portable_data_hash'], "Not found expected input param value")
378 assert_equal(input_params['selection_name'], collection['name'], "Not found expected input selection name")
381 # "Run" button present and enabled
382 page.assert_no_selector 'a.disabled,button.disabled', text: 'Run'
383 first('a,button', text: 'Run').click
385 # Pipeline is running. We have a "Pause" button instead now.
386 page.assert_no_selector 'a,button', text: 'Run'
387 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
388 page.assert_selector 'a,button', text: 'Pause'
390 # Since it is test env, no jobs are created to run. So, graph not visible
391 assert_not page.has_text? 'Graph'
395 [1, 0], # run time 0 minutes
396 [10, 17*60*60 + 51*60], # run time 17 hours and 51 minutes
397 ].each do |index, run_time|
398 test "pipeline start and finish time display #{index}" do
399 visit page_with_token("user1_with_load", "/pipeline_instances/zzzzz-d1hrv-10pipelines0#{index.to_s.rjust(3, '0')}")
401 assert page.has_text? 'This pipeline started at'
402 page_text = page.text
404 match = /This pipeline started at (.*)\. It failed after (.*) seconds at (.*)\. Check the Log/.match page_text
405 assert_not_nil(match, 'Did not find text - This pipeline started at . . . ')
408 finished_at = match[3]
409 assert_not_nil(start_at, 'Did not find start_at time')
410 assert_not_nil(finished_at, 'Did not find finished_at time')
412 # start and finished time display is of the format '2:20 PM 10/20/2014'
413 start_time = DateTime.strptime(start_at, '%H:%M %p %m/%d/%Y').to_time
414 finished_time = DateTime.strptime(finished_at, '%H:%M %p %m/%d/%Y').to_time
415 assert_equal(run_time, finished_time-start_time,
416 "Time difference did not match for start_at #{start_at}, finished_at #{finished_at}, ran_for #{match[2]}")
421 ['fuse', nil, 2, 20], # has 2 as of 11-07-2014
422 ['fuse', 'FUSE project', 1, 1], # 1 with this name
423 ['user1_with_load', nil, 30, 100], # has 37 as of 11-07-2014
424 ['user1_with_load', 'pipeline_10', 2, 2], # 2 with this name
425 ['user1_with_load', '000010pipelines', 10, 10], # owned_by the project zzzzz-j7d0g-000010pipelines
426 ['user1_with_load', '000025pipelines', 25, 25], # owned_by the project zzzzz-j7d0g-000025pipelines, two pages
427 ['admin', nil, 40, 200],
428 ['admin', 'FUSE project', 1, 1],
429 ['admin', 'pipeline_10', 2, 2],
430 ['active', 'containing at least two', 2, 100],
431 ['active', nil, 10, 100],
432 ['active', 'no such match', 0, 0],
433 ].each do |user, search_filter, expected_min, expected_max|
434 test "scroll pipeline instances page for #{user} with search filter #{search_filter}
435 and expect #{expected_min} <= found_items <= #{expected_max}" do
436 visit page_with_token(user, "/pipeline_instances")
439 find('.recent-pipeline-instances-filterable-control').set(search_filter)
440 # Wait for 250ms debounce timer (see filterable.js)
445 page_scrolls = expected_max/20 + 2 # scroll num_pages+2 times to test scrolling is disabled when it should be
446 within('.arv-recent-pipeline-instances') do
447 (0..page_scrolls).each do |i|
448 page.driver.scroll_to 0, 999000
456 # Verify that expected number of pipeline instances are found
457 found_items = page.all('tr[data-kind="arvados#pipelineInstance"]')
458 found_count = found_items.count
459 if expected_min == expected_max
460 assert_equal(true, found_count == expected_min,
461 "Not found expected number of items. Expected #{expected_min} and found #{found_count}")
462 assert page.has_no_text? 'request failed'
464 assert_equal(true, found_count>=expected_min,
465 "Found too few items. Expected at least #{expected_min} and found #{found_count}")
466 assert_equal(true, found_count<=expected_max,
467 "Found too many items. Expected at most #{expected_max} and found #{found_count}")