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 # "Run" button is now enabled
74 page.assert_no_selector 'a.disabled,button.disabled', text: 'Run'
76 first('a,button', text: 'Run').click
78 # Pipeline is running. We have a "Pause" button instead now.
79 page.assert_selector 'a,button', text: 'Pause'
80 find('a,button', text: 'Pause').click
82 # Pipeline is stopped. It should now be in paused state and Runnable again.
83 assert page.has_text? 'Paused'
84 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
85 page.assert_selector 'a,button', text: 'Re-run with latest'
86 page.assert_selector 'a,button', text: 'Re-run options'
88 # Since it is test env, no jobs are created to run. So, graph not visible
89 assert_not page.has_text? 'Graph'
92 # Create a pipeline instance from within a project and run
93 test 'Create pipeline inside a project and run' do
94 visit page_with_token('active_trustedclient')
96 # Go over to the collections page and select something
98 within('tr', text: 'GNU_General_Public_License') do
99 find('input[type=checkbox]').click
101 find('#persistent-selection-count').click
103 # Add this collection to the project using collections menu from top nav
105 find("#projects-menu").click
106 find('.dropdown-menu a,button', text: 'A Project').click
107 find('.btn', text: 'Add data').click
108 within('.modal-dialog') do
110 first('span', text: 'foo_tag').click
111 find('.btn', text: 'Add').click
113 using_wait_time(Capybara.default_wait_time * 3) do
117 create_and_run_pipeline_in_aproject true
120 # Create a pipeline instance from without a project
121 test 'Run a pipeline from dashboard' do
122 visit page_with_token('active_trustedclient')
123 create_and_run_pipeline_in_aproject false
126 # Test that the portable_data_hash is recorded when choosing an
127 # input collection for a pipeline
128 test 'pipeline input collections are recorded with portable_data_hash' do
129 visit page_with_token('active_trustedclient')
131 template = api_fixture('pipeline_templates')['simple_pipeline']
133 visit '/pipeline_templates'
134 within('tr', text: template['name']) do
135 find('a,button', text: 'Run').click
139 project = api_fixture('groups')['aproject']
140 within('.modal-dialog') do
141 find('.selectable', text: project['name']).click
142 find('button', text: 'Choose').click
145 # find the collection input field
146 input = page.all('a', text: 'Choose').select { |a|
147 a[:href] =~ /Choose.a.dataset.for.simple.pipeline.input/
149 assert_not_empty input
152 # Select a collection
153 col = api_fixture('collections')['collection_input_for_simple_pipeline']
154 within('.modal-dialog') do
155 find('div.selectable', text: col['name']).click
156 find('button', text: 'OK').click
159 # The collection's portable_data_hash, name, and uuid should have
160 # been recorded, respectively, as the value, selection_name and selection_uuid
161 # for this component's input script_parameter.
162 click_link 'Advanced'
163 click_link 'API response'
164 api_response = JSON.parse(find('div#advanced_api_response pre').text)
165 input_params = api_response['components']['foo_component']['script_parameters']['input']
166 assert_equal input_params['value'], col['portable_data_hash']
167 assert_equal input_params['selection_name'], col['name']
168 assert_equal input_params['selection_uuid'], col['uuid']
171 test 'view pipeline with job and see graph' do
172 visit page_with_token('active_trustedclient')
174 visit '/pipeline_instances'
175 assert page.has_text? 'pipeline_with_job'
177 find('a', text: 'pipeline_with_job').click
179 # since the pipeline component has a job, expect to see the graph
180 assert page.has_text? 'Graph'
182 assert page.has_text? 'script_version'
185 test 'pipeline description' do
186 visit page_with_token('active_trustedclient')
188 visit '/pipeline_instances'
189 assert page.has_text? 'pipeline_with_job'
191 find('a', text: 'pipeline_with_job').click
193 within('.arv-description-as-subtitle') do
194 find('.fa-pencil').click
195 find('.editable-input textarea').set('*Textile description for pipeline instance*')
196 find('.editable-submit').click
201 assert page.has_no_text? '*Textile description for pipeline instance*'
202 assert page.has_text? 'Textile description for pipeline instance'
205 test "JSON popup available for strange components" do
206 uuid = api_fixture("pipeline_instances")["components_is_jobspec"]["uuid"]
207 visit page_with_token("active", "/pipeline_instances/#{uuid}")
208 click_on "Components"
209 assert(page.has_no_text?("script_parameters"),
210 "components JSON visible without popup")
211 click_on "Show components JSON"
212 assert(page.has_text?("script_parameters"),
213 "components JSON not found")
216 PROJECT_WITH_SEARCH_COLLECTION = "A Subproject"
217 def check_parameter_search(proj_name)
218 template = api_fixture("pipeline_templates")["parameter_with_search"]
219 search_text = template["components"]["with-search"]["script_parameters"]["input"]["search_for"]
220 visit page_with_token("active", "/pipeline_templates/#{template['uuid']}")
221 click_on "Run this pipeline"
222 within(".modal-dialog") do # Set project for the new pipeline instance
223 find(".selectable", text: proj_name).click
226 assert(has_text?("This pipeline was created from the template"), "did not land on pipeline instance page")
227 first("a.btn,button", text: "Choose").click
228 within(".modal-body") do
229 if (proj_name != PROJECT_WITH_SEARCH_COLLECTION)
230 # Switch finder modal to Subproject to find the Collection.
232 click_on PROJECT_WITH_SEARCH_COLLECTION
234 assert_equal(search_text, first("input").value,
235 "parameter search not preseeded")
236 assert(has_text?(api_fixture("collections")["baz_collection_name_in_asubproject"]["name"]),
237 "baz Collection not in preseeded search results")
241 test "Workbench respects search_for parameter in templates" do
242 check_parameter_search(PROJECT_WITH_SEARCH_COLLECTION)
245 test "Workbench preserves search_for parameter after project switch" do
246 check_parameter_search("A Project")
250 ['active', false, false, false],
251 ['active', false, false, true],
252 ['active', true, false, false],
253 ['active', true, true, false],
254 ['active', true, false, true],
255 ['active', true, true, true],
256 ['project_viewer', false, false, true],
257 ['project_viewer', true, false, true],
258 ['project_viewer', true, true, true],
259 ].each do |user, with_options, choose_options, in_aproject|
260 test "Rerun pipeline instance as #{user} using options #{with_options} #{choose_options} in #{in_aproject}" do
261 visit page_with_token('active')
264 find("#projects-menu").click
265 find('.dropdown-menu a,button', text: 'A Project').click
268 create_and_run_pipeline_in_aproject in_aproject
269 instance_path = current_path
272 find('a,button', text: 'Pause').click
273 assert page.has_text? 'Paused'
274 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
275 page.assert_selector 'a,button', text: 'Re-run with latest'
276 page.assert_selector 'a,button', text: 'Re-run options'
278 # Pipeline can be re-run now. Access it as the specified user, and re-run
279 if user == 'project_viewer'
280 visit page_with_token(user, instance_path)
281 assert page.has_text? 'A Project'
282 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
283 page.assert_selector 'a,button', text: 'Re-run with latest'
284 page.assert_selector 'a,button', text: 'Re-run options'
287 # Now re-run the pipeline
289 find('a,button', text: 'Re-run options').click
290 within('.modal-dialog') do
291 page.assert_selector 'a,button', text: 'Copy and edit inputs'
292 page.assert_selector 'a,button', text: 'Run now'
294 find('button', text: 'Copy and edit inputs').click
296 find('button', text: 'Run now').click
300 find('a,button', text: 'Re-run with latest').click
303 # Verify that the newly created instance is created in the right project.
304 # In case of project_viewer user, since the use cannot write to the project,
305 # the pipeline should have been created in the user's Home project.
306 rerun_instance_path = current_path
307 assert_not_equal instance_path, rerun_instance_path, 'Rerun instance path expected to be different'
308 assert page.has_text? 'Home'
309 if in_aproject && (user != 'project_viewer')
310 assert page.has_text? 'A Project'
312 assert page.has_no_text? 'A Project'
317 # Create and run a pipeline for 'Two Part Pipeline Template' in 'A Project'
318 def create_and_run_pipeline_in_aproject in_aproject
319 # create a pipeline instance
320 find('.btn', text: 'Run a pipeline').click
321 within('.modal-dialog') do
322 find('.selectable', text: 'Two Part Pipeline Template').click
323 find('.btn', text: 'Next: choose inputs').click
326 assert find('p', text: 'Provide a value')
328 find('div.form-group', text: 'Foo/bar pair').
329 find('.btn', text: 'Choose').
332 within('.modal-dialog') do
334 assert_selector 'button.dropdown-toggle', text: 'A Project'
337 assert_selector 'button.dropdown-toggle', text: 'Home'
340 click_link "A Project"
343 first('span', text: 'foo_tag').click
344 find('button', text: 'OK').click
348 # "Run" button present and enabled
349 page.assert_no_selector 'a.disabled,button.disabled', text: 'Run'
350 first('a,button', text: 'Run').click
352 # Pipeline is running. We have a "Pause" button instead now.
353 page.assert_no_selector 'a,button', text: 'Run'
354 page.assert_no_selector 'a.disabled,button.disabled', text: 'Resume'
355 page.assert_selector 'a,button', text: 'Pause'
357 # Since it is test env, no jobs are created to run. So, graph not visible
358 assert_not page.has_text? 'Graph'
362 [0, 0], # run time 0 minutes
363 [9, 17*60*60 + 51*60], # run time 17 hours and 51 minutes
364 ].each do |index, run_time|
365 test "pipeline start and finish time display #{index}" do
366 visit page_with_token("user1_with_load", "/pipeline_instances/zzzzz-d1hrv-10pipelines0#{index.to_s.rjust(3, '0')}")
368 assert page.has_text? 'This pipeline started at'
369 page_text = page.text
370 match = /This pipeline started at (.*)\. It failed after (.*) seconds at (.*)\. Check the Log/.match page_text
373 finished_at = match[3]
375 # start and finished time display is of the format '2:20 PM 10/20/2014'
376 start_time = DateTime.strptime(start_at, '%I:%M %p %m/%d/%Y').to_time
377 finished_time = DateTime.strptime(finished_at, '%I:%M %p %m/%d/%Y').to_time
379 assert_equal(run_time, finished_time-start_time,
380 "Time difference did not match for start_at #{start_at}, finished_at #{finished_at}, ran_for #{match[2]}")