1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 require 'integration_helper'
7 class PipelineInstancesTest < ActionDispatch::IntegrationTest
12 def parse_browser_timestamp t
13 # Timestamps are displayed in the browser's time zone (which can
14 # differ from ours) and they come from toLocaleTimeString (which
15 # means they don't necessarily tell us which time zone they're
16 # using). In order to make sense of them, we need to ask the
17 # browser to parse them and generate a timestamp that can be
20 # Note: Even with all this help, phantomjs seem to behave badly
21 # when parsing timestamps on the other side of a DST transition.
22 # See skipped tests below.
24 # In some locales (e.g., en_CA.UTF-8) Firefox can't parse what its
25 # own toLocaleString() puts out.
26 t.sub!(/(\d\d\d\d)-(\d\d)-(\d\d)/, '\2/\3/\1')
28 if /(\d+:\d+ [AP]M) (\d+\/\d+\/\d+)/ =~ t
29 # Currently dates.js renders timestamps as
30 # '{t.toLocaleTimeString()} {t.toLocaleDateString()}' which even
31 # en_US browsers can't make sense of. First we need to flip it
32 # around so it looks like what toLocaleString() would have made.
33 t = $~[2] + ', ' + $~[1]
36 utc = page.evaluate_script("new Date('#{t}').toUTCString()")
37 DateTime.parse(utc).to_time
40 test 'view pipeline with job and see graph' do
41 visit page_with_token('active_trustedclient', '/pipeline_instances')
42 assert page.has_text? 'pipeline_with_job'
44 find('a', text: 'pipeline_with_job').click
46 # since the pipeline component has a job, expect to see the graph
47 assert page.has_text? 'Graph'
49 page.assert_selector "#provenance_graph"
52 test "JSON popup available for strange components" do
53 uuid = api_fixture("pipeline_instances")["components_is_jobspec"]["uuid"]
54 visit page_with_token("active", "/pipeline_instances/#{uuid}")
56 assert(page.has_no_text?("script_parameters"),
57 "components JSON visible without popup")
58 click_on "Show components JSON"
59 assert(page.has_text?("script_parameters"),
60 "components JSON not found")
63 def create_pipeline_from(template_name, project_name="Home")
64 # Visit the named pipeline template and create a pipeline instance from it.
65 # The instance will be created under the named project.
66 template_uuid = api_fixture("pipeline_templates", template_name, "uuid")
67 visit page_with_token("active", "/pipeline_templates/#{template_uuid}")
68 click_on "Run this pipeline"
69 within(".modal-dialog") do # FIXME: source of 3 test errors
70 # Set project for the new pipeline instance
71 find(".selectable", text: project_name).click
74 assert(has_text?("This pipeline was created from the template"),
75 "did not land on pipeline instance page")
79 ['user1_with_load', 'zzzzz-d1hrv-10pipelines0001', 0], # run time 0 minutes
80 ['user1_with_load', 'zzzzz-d1hrv-10pipelines0010', 17*60*60 + 51*60], # run time 17 hours and 51 minutes
81 ['active', 'zzzzz-d1hrv-runningpipeline', nil], # state = running
82 ].each do |user, uuid, run_time|
83 test "pipeline start and finish time display for #{uuid}" do
84 need_selenium 'to parse timestamps correctly across DST boundaries'
85 visit page_with_token(user, "/pipeline_instances/#{uuid}")
87 regexp = "This pipeline started at (.+?)\\. "
89 regexp += "It failed after (.+?) at (.+?)\\. Check the Log"
91 regexp += "It has been active for \\d"
93 assert_match /#{regexp}/, page.text
97 # match again to capture (.*)
98 _, started, duration, finished = *(/#{regexp}/.match(page.text))
101 parse_browser_timestamp(finished) - parse_browser_timestamp(started),
102 "expected: #{run_time}, got: started #{started}, finished #{finished}, duration #{duration}")
107 ['fuse', nil, 2, 20], # has 2 as of 11-07-2014
108 ['user1_with_load', '000025pipelines', 25, 25], # owned_by the project zzzzz-j7d0g-000025pipelines, two pages
109 ['admin', 'pipeline_20', 1, 1],
110 ['active', 'no such match', 0, 0],
111 ].each do |user, search_filter, expected_min, expected_max|
112 test "scroll pipeline instances page for #{user} with search filter #{search_filter}
113 and expect #{expected_min} <= found_items <= #{expected_max}" do
114 visit page_with_token(user, "/pipeline_instances")
117 find('.recent-pipeline-instances-filterable-control').set(search_filter)
118 # Wait for 250ms debounce timer (see filterable.js)
123 page_scrolls = expected_max/20 + 2 # scroll num_pages+2 times to test scrolling is disabled when it should be
124 within('.arv-recent-pipeline-instances') do
125 (0..page_scrolls).each do |i|
126 page.driver.scroll_to 0, 999000
134 # Verify that expected number of pipeline instances are found
135 found_items = page.all('tr[data-kind="arvados#pipelineInstance"]')
136 found_count = found_items.count
137 if expected_min == expected_max
138 assert_equal(true, found_count == expected_min,
139 "Not found expected number of items. Expected #{expected_min} and found #{found_count}")
140 assert page.has_no_text? 'request failed'
142 assert_equal(true, found_count>=expected_min,
143 "Found too few items. Expected at least #{expected_min} and found #{found_count}")
144 assert_equal(true, found_count<=expected_max,
145 "Found too many items. Expected at most #{expected_max} and found #{found_count}")
150 test 'render job run time when job record is inaccessible' do
151 pi = api_fixture('pipeline_instances', 'has_component_with_completed_jobs')
152 visit page_with_token 'active', '/pipeline_instances/' + pi['uuid']
153 assert_text 'Queued for '
156 test "job logs linked for running pipeline" do
157 pi = api_fixture("pipeline_instances", "running_pipeline_with_complete_job")
158 visit(page_with_token("active", "/pipeline_instances/#{pi['uuid']}"))
159 find(:xpath, "//a[@href='#Log']").click
161 assert_text "Log for previous"
162 log_link = find("a", text: "Log for previous")
163 assert_includes(log_link[:href],
164 "/jobs/#{pi["components"]["previous"]["job"]["uuid"]}#Log")
165 assert_selector "#event_log_div"
169 test "job logs linked for complete pipeline" do
170 pi = api_fixture("pipeline_instances", "complete_pipeline_with_two_jobs")
171 visit(page_with_token("active", "/pipeline_instances/#{pi['uuid']}"))
172 find(:xpath, "//a[@href='#Log']").click
174 assert_text "Log for previous"
175 pi["components"].each do |cname, cspec|
176 log_link = find("a", text: "Log for #{cname}")
177 assert_includes(log_link[:href], "/jobs/#{cspec["job"]["uuid"]}#Log")
179 assert_no_selector "#event_log_div"
183 test "job logs linked for failed pipeline" do
184 pi = api_fixture("pipeline_instances", "failed_pipeline_with_two_jobs")
185 visit(page_with_token("active", "/pipeline_instances/#{pi['uuid']}"))
186 find(:xpath, "//a[@href='#Log']").click
188 assert_text "Log for previous"
189 pi["components"].each do |cname, cspec|
190 log_link = find("a", text: "Log for #{cname}")
191 assert_includes(log_link[:href], "/jobs/#{cspec["job"]["uuid"]}#Log")
193 assert_no_selector "#event_log_div"