3 class PipelineInstancesControllerTest < ActionController::TestCase
4 include PipelineInstancesHelper
6 def create_instance_long_enough_to(instance_attrs={})
7 # create 'two_part' pipeline with the given instance attributes
8 pt_fixture = api_fixture('pipeline_templates')['two_part']
10 pipeline_instance: instance_attrs.merge({
11 pipeline_template_uuid: pt_fixture['uuid']
14 }, session_for(:active)
15 assert_response :success
16 pi_uuid = assigns(:object).uuid
17 assert_not_nil assigns(:object)
20 yield pi_uuid, pt_fixture
22 # delete the pipeline instance
24 PipelineInstance.where(uuid: pi_uuid).first.destroy
27 test "pipeline instance components populated after create" do
28 create_instance_long_enough_to do |new_instance_uuid, template_fixture|
29 assert_equal(template_fixture['components'].to_json,
30 assigns(:object).components.to_json)
34 test "can render pipeline instance with tagged collections" do
35 # Make sure to pass in a tagged collection to test that part of the rendering behavior.
37 {id: api_fixture("pipeline_instances")["pipeline_with_tagged_collection_input"]["uuid"]},
39 assert_response :success
42 test "update script_parameters one at a time using merge param" do
43 template_fixture = api_fixture('pipeline_templates')['two_part']
45 id: api_fixture("pipeline_instances")["pipeline_to_merge_params"]["uuid"],
62 }, session_for(:active)
63 assert_response :success
64 assert_not_nil assigns(:object)
65 orig_params = template_fixture['components']['part-two']['script_parameters']
66 new_params = assigns(:object).components[:'part-two'][:script_parameters]
67 orig_params.keys.each do |k|
68 unless %w(integer_with_value plain_string).index(k)
69 assert_equal orig_params[k].to_json, new_params[k.to_sym].to_json
74 test "component rendering copes with unexpected components format" do
76 {id: api_fixture("pipeline_instances")["components_is_jobspec"]["uuid"]},
78 assert_response :success
81 test "dates in JSON components are parsed" do
83 {id: api_fixture('pipeline_instances')['has_component_with_completed_jobs']['uuid']},
85 assert_response :success
86 assert_not_nil assigns(:object)
87 assert_not_nil assigns(:object).components[:foo][:job]
88 start_at = assigns(:object).components[:foo][:job][:started_at]
89 start_at = Time.parse(start_at) if (start_at.andand.class == String)
90 assert start_at.is_a? Time
91 finished_at = assigns(:object).components[:foo][:job][:started_at]
92 finished_at = Time.parse(finished_at) if (finished_at.andand.class == String)
93 assert finished_at.is_a? Time
96 # The next two tests ensure that a pipeline instance can be copied
97 # when the template has components that do not exist in the
98 # instance (ticket #4000).
100 test "copy pipeline instance with components=use_latest" do
103 id: api_fixture('pipeline_instances')['pipeline_with_newer_template']['uuid'],
104 components: 'use_latest',
105 script: 'use_latest',
107 state: 'RunningOnServer'
110 session_for(:active))
112 assert_not_nil assigns(:object)
114 # Component 'foo' has script parameters only in the pipeline instance.
115 # Component 'bar' is present only in the pipeline_template.
116 # Test that the copied pipeline instance includes parameters for
117 # component 'foo' from the source instance, and parameters for
118 # component 'bar' from the source template.
120 assert_not_nil assigns(:object).components[:foo]
121 foo = assigns(:object).components[:foo]
122 assert_not_nil foo[:script_parameters]
123 assert_not_nil foo[:script_parameters][:input]
124 assert_equal 'foo instance input', foo[:script_parameters][:input][:title]
126 assert_not_nil assigns(:object).components[:bar]
127 bar = assigns(:object).components[:bar]
128 assert_not_nil bar[:script_parameters]
129 assert_not_nil bar[:script_parameters][:input]
130 assert_equal 'bar template input', bar[:script_parameters][:input][:title]
133 test "copy pipeline instance on newer template works with script=use_same" do
136 id: api_fixture('pipeline_instances')['pipeline_with_newer_template']['uuid'],
137 components: 'use_latest',
140 state: 'RunningOnServer'
143 session_for(:active))
145 assert_not_nil assigns(:object)
147 # Test that relevant component parameters were copied from both
148 # the source instance and source template, respectively (see
151 assert_not_nil assigns(:object).components[:foo]
152 foo = assigns(:object).components[:foo]
153 assert_not_nil foo[:script_parameters]
154 assert_not_nil foo[:script_parameters][:input]
155 assert_equal 'foo instance input', foo[:script_parameters][:input][:title]
157 assert_not_nil assigns(:object).components[:bar]
158 bar = assigns(:object).components[:bar]
159 assert_not_nil bar[:script_parameters]
160 assert_not_nil bar[:script_parameters][:input]
161 assert_equal 'bar template input', bar[:script_parameters][:input][:title]
164 test "generate graph" do
168 pipeline_for_graph = {
170 uuid: 'zzzzz-d1hrv-9fm8l10i9z2kqc9',
175 script_version: 'master',
176 job: {uuid: 'zzzzz-8i9sb-graphstage10000'},
177 output_uuid: 'zzzzz-4zz18-bv31uwvy3neko22'
182 script_version: 'master',
184 input: 'fa7aeb5140e2848d39b416daeef4ffc5+45'
186 job: {uuid: 'zzzzz-8i9sb-graphstage20000'},
187 output_uuid: 'zzzzz-4zz18-uukreo9rbgwsujx'
192 @controller.params['tab_pane'] = "Graph"
193 provenance, pips = @controller.graph([pipeline_for_graph])
195 graph_test_collection1 = find_fixture Collection, "graph_test_collection1"
196 stage1 = find_fixture Job, "graph_stage1"
197 stage2 = find_fixture Job, "graph_stage2"
199 ['component_zzzzz-d1hrv-9fm8l10i9z2kqc9_stage1',
200 'component_zzzzz-d1hrv-9fm8l10i9z2kqc9_stage2',
205 pipeline_for_graph[:components][:stage1][:output_uuid],
206 pipeline_for_graph[:components][:stage2][:output_uuid]
209 assert_not_nil provenance[k], "Expected key #{k} in provenance set"
210 assert_equal 1, pips[k], "Expected key #{k} in pips set" if !k.start_with? "component_"
213 prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
214 :request => RequestDuck,
215 :all_script_parameters => true,
216 :combine_jobs => :script_and_version,
218 :only_components => true }
220 stage1_id = "#{stage1[:script]}_#{stage1[:script_version]}_#{Digest::MD5.hexdigest(stage1[:script_parameters].to_json)}"
221 stage2_id = "#{stage2[:script]}_#{stage2[:script_version]}_#{Digest::MD5.hexdigest(stage2[:script_parameters].to_json)}"
223 stage1_out = stage1[:output].gsub('+','\\\+')
225 assert_match /#{stage1_id}->#{stage1_out}/, prov_svg
227 assert_match /#{stage1_out}->#{stage2_id}/, prov_svg
231 test "generate graph compare" do
235 pipeline_for_graph1 = {
237 uuid: 'zzzzz-d1hrv-9fm8l10i9z2kqc9',
242 script_version: 'master',
243 job: {uuid: 'zzzzz-8i9sb-graphstage10000'},
244 output_uuid: 'zzzzz-4zz18-bv31uwvy3neko22'
249 script_version: 'master',
251 input: 'fa7aeb5140e2848d39b416daeef4ffc5+45'
253 job: {uuid: 'zzzzz-8i9sb-graphstage20000'},
254 output_uuid: 'zzzzz-4zz18-uukreo9rbgwsujx'
259 pipeline_for_graph2 = {
261 uuid: 'zzzzz-d1hrv-9fm8l10i9z2kqc0',
266 script_version: 'master',
267 job: {uuid: 'zzzzz-8i9sb-graphstage10000'},
268 output_uuid: 'zzzzz-4zz18-bv31uwvy3neko22'
273 script_version: 'master',
276 job: {uuid: 'zzzzz-8i9sb-graphstage30000'},
277 output_uuid: 'zzzzz-4zz18-uukreo9rbgwsujj'
282 @controller.params['tab_pane'] = "Graph"
283 provenance, pips = @controller.graph([pipeline_for_graph1, pipeline_for_graph2])
285 collection1 = find_fixture Collection, "graph_test_collection1"
287 stage1 = find_fixture Job, "graph_stage1"
288 stage2 = find_fixture Job, "graph_stage2"
289 stage3 = find_fixture Job, "graph_stage3"
291 [['component_zzzzz-d1hrv-9fm8l10i9z2kqc9_stage1', nil],
292 ['component_zzzzz-d1hrv-9fm8l10i9z2kqc9_stage2', nil],
293 ['component_zzzzz-d1hrv-9fm8l10i9z2kqc0_stage1', nil],
294 ['component_zzzzz-d1hrv-9fm8l10i9z2kqc0_stage2', nil],
301 [pipeline_for_graph1[:components][:stage1][:output_uuid], 3],
302 [pipeline_for_graph1[:components][:stage2][:output_uuid], 1],
303 [pipeline_for_graph2[:components][:stage2][:output_uuid], 2]
305 assert_not_nil provenance[k[0]], "Expected key #{k[0]} in provenance set"
306 assert_equal k[1], pips[k[0]], "Expected key #{k} in pips" if !k[0].start_with? "component_"
309 prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
310 :request => RequestDuck,
311 :all_script_parameters => true,
312 :combine_jobs => :script_and_version,
314 :only_components => true }
316 collection1_id = collection1.portable_data_hash.gsub('+','\\\+')
318 stage2_id = "#{stage2[:script]}_#{stage2[:script_version]}_#{Digest::MD5.hexdigest(stage2[:script_parameters].to_json)}"
319 stage3_id = "#{stage3[:script]}_#{stage3[:script_version]}_#{Digest::MD5.hexdigest(stage3[:script_parameters].to_json)}"
321 stage2_out = stage2[:output].gsub('+','\\\+')
322 stage3_out = stage3[:output].gsub('+','\\\+')
324 assert_match /#{collection1_id}->#{stage2_id}/, prov_svg
325 assert_match /#{collection1_id}->#{stage3_id}/, prov_svg
327 assert_match /#{stage2_id}->#{stage2_out}/, prov_svg
328 assert_match /#{stage3_id}->#{stage3_out}/, prov_svg