1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class PipelineInstancesControllerTest < ActionController::TestCase
8 include PipelineInstancesHelper
10 def create_instance_long_enough_to(instance_attrs={})
11 # create 'two_part' pipeline with the given instance attributes
12 pt_fixture = api_fixture('pipeline_templates')['two_part']
13 post :create, params: {
14 pipeline_instance: instance_attrs.merge({
15 pipeline_template_uuid: pt_fixture['uuid']
18 }, session: session_for(:active)
19 assert_response :success
20 pi_uuid = assigns(:object).uuid
21 assert_not_nil assigns(:object)
24 yield pi_uuid, pt_fixture
26 # delete the pipeline instance
28 PipelineInstance.where(uuid: pi_uuid).first.destroy
31 test "can render pipeline instance with tagged collections" do
32 # Make sure to pass in a tagged collection to test that part of the rendering behavior.
34 params: {id: api_fixture("pipeline_instances")["pipeline_with_tagged_collection_input"]["uuid"]},
35 session: session_for(:active))
36 assert_response :success
39 test "component rendering copes with unexpected components format" do
41 params: {id: api_fixture("pipeline_instances")["components_is_jobspec"]["uuid"]},
42 session: session_for(:active))
43 assert_response :success
46 test "dates in JSON components are parsed" do
48 params: {id: api_fixture('pipeline_instances')['has_component_with_completed_jobs']['uuid']},
49 session: session_for(:active))
50 assert_response :success
51 assert_not_nil assigns(:object)
52 assert_not_nil assigns(:object).components[:foo][:job]
53 start_at = assigns(:object).components[:foo][:job][:started_at]
54 start_at = Time.parse(start_at) if (start_at.andand.class == String)
55 assert start_at.is_a? Time
56 finished_at = assigns(:object).components[:foo][:job][:started_at]
57 finished_at = Time.parse(finished_at) if (finished_at.andand.class == String)
58 assert finished_at.is_a? Time
61 # The next two tests ensure that a pipeline instance can be copied
62 # when the template has components that do not exist in the
63 # instance (ticket #4000).
65 test "generate graph" do
69 pipeline_for_graph = {
71 uuid: 'zzzzz-d1hrv-9fm8l10i9z2kqc9',
76 script_version: 'master',
77 job: {uuid: 'zzzzz-8i9sb-graphstage10000'},
78 output_uuid: 'zzzzz-4zz18-bv31uwvy3neko22'
83 script_version: 'master',
85 input: 'fa7aeb5140e2848d39b416daeef4ffc5+45'
87 job: {uuid: 'zzzzz-8i9sb-graphstage20000'},
88 output_uuid: 'zzzzz-4zz18-uukreo9rbgwsujx'
93 @controller.params['tab_pane'] = "Graph"
94 provenance, pips = @controller.graph([pipeline_for_graph])
96 graph_test_collection1 = find_fixture Collection, "graph_test_collection1"
97 stage1 = find_fixture Job, "graph_stage1"
98 stage2 = find_fixture Job, "graph_stage2"
100 ['component_zzzzz-d1hrv-9fm8l10i9z2kqc9_stage1',
101 'component_zzzzz-d1hrv-9fm8l10i9z2kqc9_stage2',
106 pipeline_for_graph[:components][:stage1][:output_uuid],
107 pipeline_for_graph[:components][:stage2][:output_uuid]
110 assert_not_nil provenance[k], "Expected key #{k} in provenance set"
111 assert_equal 1, pips[k], "Expected key #{k} in pips set" if !k.start_with? "component_"
114 prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
115 :request => RequestDuck,
116 :all_script_parameters => true,
117 :combine_jobs => :script_and_version,
119 :only_components => true }
121 stage1_id = "#{stage1[:script]}_#{stage1[:script_version]}_#{Digest::MD5.hexdigest(stage1[:script_parameters].to_json)}"
122 stage2_id = "#{stage2[:script]}_#{stage2[:script_version]}_#{Digest::MD5.hexdigest(stage2[:script_parameters].to_json)}"
124 stage1_out = stage1[:output].gsub('+','\\\+')
126 assert_match /#{stage1_id}->#{stage1_out}/, prov_svg
128 assert_match /#{stage1_out}->#{stage2_id}/, prov_svg
132 test "generate graph compare" do
136 pipeline_for_graph1 = {
138 uuid: 'zzzzz-d1hrv-9fm8l10i9z2kqc9',
143 script_version: 'master',
144 job: {uuid: 'zzzzz-8i9sb-graphstage10000'},
145 output_uuid: 'zzzzz-4zz18-bv31uwvy3neko22'
150 script_version: 'master',
152 input: 'fa7aeb5140e2848d39b416daeef4ffc5+45'
154 job: {uuid: 'zzzzz-8i9sb-graphstage20000'},
155 output_uuid: 'zzzzz-4zz18-uukreo9rbgwsujx'
160 pipeline_for_graph2 = {
162 uuid: 'zzzzz-d1hrv-9fm8l10i9z2kqc0',
167 script_version: 'master',
168 job: {uuid: 'zzzzz-8i9sb-graphstage10000'},
169 output_uuid: 'zzzzz-4zz18-bv31uwvy3neko22'
174 script_version: 'master',
177 job: {uuid: 'zzzzz-8i9sb-graphstage30000'},
178 output_uuid: 'zzzzz-4zz18-uukreo9rbgwsujj'
183 @controller.params['tab_pane'] = "Graph"
184 provenance, pips = @controller.graph([pipeline_for_graph1, pipeline_for_graph2])
186 collection1 = find_fixture Collection, "graph_test_collection1"
188 stage1 = find_fixture Job, "graph_stage1"
189 stage2 = find_fixture Job, "graph_stage2"
190 stage3 = find_fixture Job, "graph_stage3"
192 [['component_zzzzz-d1hrv-9fm8l10i9z2kqc9_stage1', nil],
193 ['component_zzzzz-d1hrv-9fm8l10i9z2kqc9_stage2', nil],
194 ['component_zzzzz-d1hrv-9fm8l10i9z2kqc0_stage1', nil],
195 ['component_zzzzz-d1hrv-9fm8l10i9z2kqc0_stage2', nil],
202 [pipeline_for_graph1[:components][:stage1][:output_uuid], 3],
203 [pipeline_for_graph1[:components][:stage2][:output_uuid], 1],
204 [pipeline_for_graph2[:components][:stage2][:output_uuid], 2]
206 assert_not_nil provenance[k[0]], "Expected key #{k[0]} in provenance set"
207 assert_equal k[1], pips[k[0]], "Expected key #{k} in pips" if !k[0].start_with? "component_"
210 prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
211 :request => RequestDuck,
212 :all_script_parameters => true,
213 :combine_jobs => :script_and_version,
215 :only_components => true }
217 collection1_id = collection1.portable_data_hash.gsub('+','\\\+')
219 stage2_id = "#{stage2[:script]}_#{stage2[:script_version]}_#{Digest::MD5.hexdigest(stage2[:script_parameters].to_json)}"
220 stage3_id = "#{stage3[:script]}_#{stage3[:script_version]}_#{Digest::MD5.hexdigest(stage3[:script_parameters].to_json)}"
222 stage2_out = stage2[:output].gsub('+','\\\+')
223 stage3_out = stage3[:output].gsub('+','\\\+')
225 assert_match /#{collection1_id}->#{stage2_id}/, prov_svg
226 assert_match /#{collection1_id}->#{stage3_id}/, prov_svg
228 assert_match /#{stage2_id}->#{stage2_out}/, prov_svg
229 assert_match /#{stage3_id}->#{stage3_out}/, prov_svg