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 # Go over to the collections page and select something
34 within('tr', text: 'GNU_General_Public_License') do
35 find('input[type=checkbox]').click
37 find('#persistent-selection-count').click
39 # Add this collection to the project
41 find("#projects-menu").click
42 find('.dropdown-menu a,button', text: 'A Project').click
43 find('.btn', text: 'Add data').click
44 within('.modal-dialog') do
46 first('span', text: 'foo_tag').click
47 find('.btn', text: 'Add').click
49 using_wait_time(Capybara.default_wait_time * 3) do
53 click_link 'Jobs and pipelines'
54 find('tr[data-kind="arvados#pipelineInstance"]', text: '(none)').
55 find('a', text: 'Show').
58 assert find('p', text: 'Provide a value')
60 find('div.form-group', text: 'Foo/bar pair').
61 find('.btn', text: 'Choose').
64 within('.modal-dialog') do
65 assert(has_text?("Foo/bar pair"),
66 "pipeline input picker missing name of input")
68 first('span', text: 'foo_tag').click
69 find('button', text: 'OK').click
73 # Ensure that the collection's portable_data_hash, uuid and name
74 # are saved in the desired places. (#4015)
76 # foo_collection_in_aproject is the collection tagged with foo_tag.
77 col = api_fixture('collections', 'foo_collection_in_aproject')
79 click_link 'API response'
80 api_response = JSON.parse(find('div#advanced_api_response pre').text)
81 input_params = api_response['components']['part-one']['script_parameters']['input']
82 assert_equal input_params['value'], col['portable_data_hash']
83 assert_equal input_params['selection_name'], col['name']
84 assert_equal input_params['selection_uuid'], col['uuid']
86 # "Run" button is now enabled
87 page.assert_no_selector 'a.disabled,button.disabled', text: 'Run'
89 first('a,button', text: 'Run').click
91 # Pipeline is running. We have a "Pause" button instead now.
92 page.assert_selector 'a,button', text: 'Pause'
93 find('a,button', text: 'Pause').click
95 # Pipeline is stopped. It should now be in paused state and Runnable again.
96 assert page.has_text? 'Paused'
97 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
98 page.assert_selector 'a,button', text: 'Re-run with latest'
99 page.assert_selector 'a,button', text: 'Re-run options'
101 # Since it is test env, no jobs are created to run. So, graph not visible
102 assert_not page.has_text? 'Graph'
105 # Create a pipeline instance from within a project and run
106 test 'Create pipeline inside a project and run' do
107 visit page_with_token('active_trustedclient')
109 # Go over to the collections page and select something
111 within('tr', text: 'GNU_General_Public_License') do
112 find('input[type=checkbox]').click
114 find('#persistent-selection-count').click
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 within('.modal-dialog') do
123 first('span', text: 'foo_tag').click
124 find('.btn', text: 'Add').click
126 using_wait_time(Capybara.default_wait_time * 3) do
130 create_and_run_pipeline_in_aproject true
133 # Create a pipeline instance from outside of a project
134 test 'Run a pipeline from dashboard' do
135 visit page_with_token('active_trustedclient')
136 create_and_run_pipeline_in_aproject false
139 test 'view pipeline with job and see graph' do
140 visit page_with_token('active_trustedclient')
142 visit '/pipeline_instances'
143 assert page.has_text? 'pipeline_with_job'
145 find('a', text: 'pipeline_with_job').click
147 # since the pipeline component has a job, expect to see the graph
148 assert page.has_text? 'Graph'
150 page.assert_selector "#provenance_graph"
153 test 'pipeline description' do
154 visit page_with_token('active_trustedclient')
156 visit '/pipeline_instances'
157 assert page.has_text? 'pipeline_with_job'
159 find('a', text: 'pipeline_with_job').click
161 within('.arv-description-as-subtitle') do
162 find('.fa-pencil').click
163 find('.editable-input textarea').set('*Textile description for pipeline instance*')
164 find('.editable-submit').click
169 assert page.has_no_text? '*Textile description for pipeline instance*'
170 assert page.has_text? 'Textile description for pipeline instance'
173 test "JSON popup available for strange components" do
174 uuid = api_fixture("pipeline_instances")["components_is_jobspec"]["uuid"]
175 visit page_with_token("active", "/pipeline_instances/#{uuid}")
176 click_on "Components"
177 assert(page.has_no_text?("script_parameters"),
178 "components JSON visible without popup")
179 click_on "Show components JSON"
180 assert(page.has_text?("script_parameters"),
181 "components JSON not found")
184 PROJECT_WITH_SEARCH_COLLECTION = "A Subproject"
185 def check_parameter_search(proj_name)
186 template = api_fixture("pipeline_templates")["parameter_with_search"]
187 search_text = template["components"]["with-search"]["script_parameters"]["input"]["search_for"]
188 visit page_with_token("active", "/pipeline_templates/#{template['uuid']}")
189 click_on "Run this pipeline"
190 within(".modal-dialog") do # Set project for the new pipeline instance
191 find(".selectable", text: proj_name).click
194 assert(has_text?("This pipeline was created from the template"), "did not land on pipeline instance page")
195 first("a.btn,button", text: "Choose").click
196 within(".modal-body") do
197 if (proj_name != PROJECT_WITH_SEARCH_COLLECTION)
198 # Switch finder modal to Subproject to find the Collection.
200 click_on PROJECT_WITH_SEARCH_COLLECTION
202 assert_equal(search_text, first("input").value,
203 "parameter search not preseeded")
204 assert(has_text?(api_fixture("collections")["baz_collection_name_in_asubproject"]["name"]),
205 "baz Collection not in preseeded search results")
209 test "Workbench respects search_for parameter in templates" do
210 check_parameter_search(PROJECT_WITH_SEARCH_COLLECTION)
213 test "Workbench preserves search_for parameter after project switch" do
214 check_parameter_search("A Project")
218 ['active', false, false, false],
219 ['active', false, false, true],
220 ['active', true, false, false],
221 ['active', true, true, false],
222 ['active', true, false, true],
223 ['active', true, true, true],
224 ['project_viewer', false, false, true],
225 ['project_viewer', true, false, true],
226 ['project_viewer', true, true, true],
227 ].each do |user, with_options, choose_options, in_aproject|
228 test "Rerun pipeline instance as #{user} using options #{with_options} #{choose_options} in #{in_aproject}" do
229 visit page_with_token('active')
232 find("#projects-menu").click
233 find('.dropdown-menu a,button', text: 'A Project').click
236 create_and_run_pipeline_in_aproject in_aproject
237 instance_path = current_path
240 find('a,button', text: 'Pause').click
241 assert page.has_text? 'Paused'
242 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
243 page.assert_selector 'a,button', text: 'Re-run with latest'
244 page.assert_selector 'a,button', text: 'Re-run options'
246 # Pipeline can be re-run now. Access it as the specified user, and re-run
247 if user == 'project_viewer'
248 visit page_with_token(user, instance_path)
249 assert page.has_text? 'A Project'
250 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
251 page.assert_selector 'a,button', text: 'Re-run with latest'
252 page.assert_selector 'a,button', text: 'Re-run options'
255 # Now re-run the pipeline
257 find('a,button', text: 'Re-run options').click
258 within('.modal-dialog') do
259 page.assert_selector 'a,button', text: 'Copy and edit inputs'
260 page.assert_selector 'a,button', text: 'Run now'
262 find('button', text: 'Copy and edit inputs').click
264 find('button', text: 'Run now').click
268 find('a,button', text: 'Re-run with latest').click
271 # Verify that the newly created instance is created in the right project.
272 # In case of project_viewer user, since the use cannot write to the project,
273 # the pipeline should have been created in the user's Home project.
274 rerun_instance_path = current_path
275 assert_not_equal instance_path, rerun_instance_path, 'Rerun instance path expected to be different'
276 assert page.has_text? 'Home'
277 if in_aproject && (user != 'project_viewer')
278 assert page.has_text? 'A Project'
280 assert page.has_no_text? 'A Project'
285 # Create and run a pipeline for 'Two Part Pipeline Template' in 'A Project'
286 def create_and_run_pipeline_in_aproject in_aproject
287 # create a pipeline instance
288 find('.btn', text: 'Run a pipeline').click
289 within('.modal-dialog') do
290 find('.selectable', text: 'Two Part Pipeline Template').click
291 find('.btn', text: 'Next: choose inputs').click
294 assert find('p', text: 'Provide a value')
296 find('div.form-group', text: 'Foo/bar pair').
297 find('.btn', text: 'Choose').
300 within('.modal-dialog') do
302 assert_selector 'button.dropdown-toggle', text: 'A Project'
305 assert_selector 'button.dropdown-toggle', text: 'Home'
308 click_link "A Project"
311 first('span', text: 'foo_tag').click
312 find('button', text: 'OK').click
316 # Ensure that the collection's portable_data_hash, uuid and name
317 # are saved in the desired places. (#4015)
319 # foo_collection_in_aproject is the collection tagged with foo_tag.
320 col = api_fixture('collections', 'foo_collection_in_aproject')
321 click_link 'Advanced'
322 click_link 'API response'
323 api_response = JSON.parse(find('div#advanced_api_response pre').text)
324 input_params = api_response['components']['part-one']['script_parameters']['input']
325 assert_equal input_params['value'], col['portable_data_hash']
326 assert_equal input_params['selection_name'], col['name']
327 assert_equal input_params['selection_uuid'], col['uuid']
329 # "Run" button present and enabled
330 page.assert_no_selector 'a.disabled,button.disabled', text: 'Run'
331 first('a,button', text: 'Run').click
333 # Pipeline is running. We have a "Pause" button instead now.
334 page.assert_no_selector 'a,button', text: 'Run'
335 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
336 page.assert_selector 'a,button', text: 'Pause'
338 # Since it is test env, no jobs are created to run. So, graph not visible
339 assert_not page.has_text? 'Graph'
343 [1, 0], # run time 0 minutes
344 [10, 17*60*60 + 51*60], # run time 17 hours and 51 minutes
345 ].each do |index, run_time|
346 test "pipeline start and finish time display #{index}" do
347 visit page_with_token("user1_with_load", "/pipeline_instances/zzzzz-d1hrv-10pipelines0#{index.to_s.rjust(3, '0')}")
349 assert page.has_text? 'This pipeline started at'
350 page_text = page.text
352 match = /This pipeline started at (.*)\. It failed after (.*) seconds at (.*)\. Check the Log/.match page_text
353 assert_not_nil(match, 'Did not find text - This pipeline started at . . . ')
356 finished_at = match[3]
357 assert_not_nil(start_at, 'Did not find start_at time')
358 assert_not_nil(finished_at, 'Did not find finished_at time')
360 # start and finished time display is of the format '2:20 PM 10/20/2014'
361 start_time = DateTime.strptime(start_at, '%H:%M %p %m/%d/%Y').to_time
362 finished_time = DateTime.strptime(finished_at, '%H:%M %p %m/%d/%Y').to_time
363 assert_equal(run_time, finished_time-start_time,
364 "Time difference did not match for start_at #{start_at}, finished_at #{finished_at}, ran_for #{match[2]}")
369 ['fuse', nil, 2, 20], # has 2 as of 11-07-2014
370 ['fuse', 'FUSE project', 1, 1], # 1 with this name
371 ['user1_with_load', nil, 30, 100], # has 37 as of 11-07-2014
372 ['user1_with_load', 'pipeline_10', 2, 2], # 2 with this name
373 ['user1_with_load', '000010pipelines', 10, 10], # owned_by the project zzzzz-j7d0g-000010pipelines
374 ['user1_with_load', '000025pipelines', 25, 25], # owned_by the project zzzzz-j7d0g-000025pipelines, two pages
375 ['admin', nil, 40, 200],
376 ['admin', 'FUSE project', 1, 1],
377 ['admin', 'pipeline_10', 2, 2],
378 ['active', 'containing at least two', 2, 100], # component description
379 ['admin', 'containing at least two', 2, 100],
380 ['active', nil, 10, 100],
381 ['active', 'no such match', 0, 0],
382 ].each do |user, search_filter, expected_min, expected_max|
383 test "scroll pipeline instances page for #{user} with search filter #{search_filter}
384 and expect more than #{expected_min} and less than #{expected_max}" do
385 visit page_with_token(user, "/pipeline_instances")
388 find('.recent-pipeline-instances-filterable-control').set(search_filter)
392 page_scrolls = expected_max/20 + 2 # scroll num_pages+2 times to test scrolling is disabled when it should be
393 within('.arv-recent-pipeline-instances') do
394 (0..page_scrolls).each do |i|
395 page.execute_script "window.scrollBy(0,999000)"
403 # Verify that expected number of pipeline instances are found
404 found_items = page.all('tr[data-kind="arvados#pipelineInstance"]')
405 found_count = found_items.count
406 if expected_min == expected_max
407 assert_equal(true, found_count == expected_min,
408 "Not found expected number of items. Expected at least #{expected_min} and found #{found_count}")
410 assert_equal(true, found_count>=expected_min,
411 "Found too few items. Expected at least #{expected_min} and found #{found_count}")
412 assert_equal(true, found_count<=expected_max,
413 "Found too many items. Expected at most #{expected_max} and found #{found_count}")