1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class PipelineInstanceTest < ActiveSupport::TestCase
9 test "check active and success for a pipeline in new state" do
10 pi = pipeline_instances :new_pipeline
12 assert_equal 'New', pi.state, 'expected state to be New for :new_pipeline'
14 # save the pipeline and expect state to be New
15 Thread.current[:user] = users(:admin)
18 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
19 assert_equal PipelineInstance::New, pi.state, 'expected state to be New for new pipeline'
22 test "check active and success for a newly created pipeline" do
23 set_user_from_auth :active
25 pi = PipelineInstance.create(state: 'Ready')
28 assert pi.valid?, 'expected newly created empty pipeline to be valid ' + pi.errors.messages.to_s
29 assert_equal 'Ready', pi.state, 'expected state to be Ready for a new empty pipeline'
32 test "update attributes for pipeline" do
33 Thread.current[:user] = users(:admin)
35 pi = pipeline_instances :new_pipeline
37 # add a component with no input and expect state to be New
38 component = {'script_parameters' => {"input_not_provided" => {"required" => true}}}
39 pi.components['first'] = component
40 components = pi.components
41 pi.update_attribute 'components', pi.components
42 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
43 assert_equal PipelineInstance::New, pi.state, 'expected state to be New after adding component with input'
44 assert_equal pi.components.size, 1, 'expected one component'
45 assert_nil pi.started_at, 'expected started_at to be nil on new pipeline instance'
46 assert_nil pi.finished_at, 'expected finished_at to be nil on new pipeline instance'
48 # add a component with no input not required
49 component = {'script_parameters' => {"input_not_provided" => {"required" => false}}}
50 pi.components['first'] = component
51 components = pi.components
52 pi.update_attribute 'components', pi.components
53 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
54 assert_equal PipelineInstance::Ready, pi.state, 'expected state to be Ready after adding component with input'
55 assert_equal pi.components.size, 1, 'expected one component'
57 # add a component with input and expect state to become Ready
58 component = {'script_parameters' => {"input" => "yyyad4b39ca5a924e481008009d94e32+210"}}
59 pi.components['first'] = component
60 components = pi.components
61 pi.update_attribute 'components', pi.components
62 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
63 assert_equal PipelineInstance::Ready, pi.state, 'expected state to be Ready after adding component with input'
64 assert_equal pi.components.size, 1, 'expected one component'
66 pi.state = PipelineInstance::RunningOnServer
68 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
69 assert_equal PipelineInstance::RunningOnServer, pi.state, 'expected state to be RunningOnServer after updating state to RunningOnServer'
70 assert_not_nil pi.started_at, 'expected started_at to have a value on a running pipeline instance'
71 assert_nil pi.finished_at, 'expected finished_at to be nil on a running pipeline instance'
73 pi.state = PipelineInstance::Paused
75 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
76 assert_equal PipelineInstance::Paused, pi.state, 'expected state to be Paused after updating state to Paused'
78 pi.state = PipelineInstance::Complete
80 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
81 assert_equal PipelineInstance::Complete, pi.state, 'expected state to be Complete after updating state to Complete'
82 assert_not_nil pi.started_at, 'expected started_at to have a value on a completed pipeline instance'
83 assert_not_nil pi.finished_at, 'expected finished_at to have a value on a completed pipeline instance'
87 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
88 assert_equal PipelineInstance::Complete, pi.state, 'expected state to be unchanged with set to a bogus value'
90 pi.state = PipelineInstance::Failed
92 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
93 assert_equal PipelineInstance::Failed, pi.state, 'expected state to be Failed after updating state to Failed'
94 assert_not_nil pi.started_at, 'expected started_at to have a value on a failed pipeline instance'
95 assert_not_nil pi.finished_at, 'expected finished_at to have a value on a failed pipeline instance'
98 test "update attributes for pipeline with two components" do
99 pi = pipeline_instances :new_pipeline
101 # add two components, one with input and one with no input and expect state to be New
102 component1 = {'script_parameters' => {"something" => "xxxad4b39ca5a924e481008009d94e32+210", "input" => "c1bad4b39ca5a924e481008009d94e32+210"}}
103 component2 = {'script_parameters' => {"something_else" => "xxxad4b39ca5a924e481008009d94e32+210", "input_missing" => {"required" => true}}}
104 pi.components['first'] = component1
105 pi.components['second'] = component2
107 Thread.current[:user] = users(:admin)
108 pi.update_attribute 'components', pi.components
110 pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
111 assert_equal PipelineInstance::New, pi.state, 'expected state to be New after adding component with input'
112 assert_equal pi.components.size, 2, 'expected two components'
115 [:has_component_with_no_script_parameters,
116 :has_component_with_empty_script_parameters].each do |pi_name|
117 test "update pipeline that #{pi_name}" do
118 pi = pipeline_instances pi_name
120 Thread.current[:user] = users(:active)
121 assert_equal PipelineInstance::Ready, pi.state