2 load 'test/functional/arvados/v1/git_setup.rb'
4 class Arvados::V1::JobsControllerTest < ActionController::TestCase
12 script_version: "master",
16 assert_response :success
17 assert_not_nil assigns(:object)
18 new_job = JSON.parse(@response.body)
19 assert_not_nil new_job['uuid']
20 assert_not_nil new_job['script_version'].match(/^[0-9a-f]{40}$/)
21 # Default: not persistent
22 assert_equal false, new_job['output_is_persistent']
25 test "normalize output and log uuids when creating job" do
26 authorize_with :active
29 script_version: "master",
30 script_parameters: {},
33 finished_at: Time.now,
36 output: 'd41d8cd98f00b204e9800998ecf8427e+0+K@xyzzy',
37 log: 'd41d8cd98f00b204e9800998ecf8427e+0+K@xyzzy'
39 assert_response :success
40 assert_not_nil assigns(:object)
41 new_job = JSON.parse(@response.body)
42 assert_equal 'd41d8cd98f00b204e9800998ecf8427e+0', new_job['log']
43 assert_equal 'd41d8cd98f00b204e9800998ecf8427e+0', new_job['output']
44 version = new_job['script_version']
46 # Make sure version doesn't get mangled by normalize
47 assert_not_nil version.match(/^[0-9a-f]{40}$/)
54 assert_equal version, JSON.parse(@response.body)['script_version']
57 test "cancel a running job" do
58 # We need to verify that "cancel" creates a trigger file, so first
59 # let's make sure there is no stale trigger file.
61 File.unlink(Rails.configuration.crunch_refresh_trigger)
65 authorize_with :active
67 id: jobs(:running).uuid,
69 cancelled_at: 4.day.ago
72 assert_response :success
73 assert_not_nil assigns(:object)
74 job = JSON.parse(@response.body)
75 assert_not_nil job['uuid']
76 assert_not_nil job['cancelled_at']
77 assert_not_nil job['cancelled_by_user_uuid']
78 assert_not_nil job['cancelled_by_client_uuid']
79 assert_equal(true, Time.parse(job['cancelled_at']) > 1.minute.ago,
80 'server should correct bogus cancelled_at ' +
83 File.exists?(Rails.configuration.crunch_refresh_trigger),
84 'trigger file should be created when job is cancelled')
87 id: jobs(:running).uuid,
92 job = JSON.parse(@response.body)
93 assert_not_nil job['cancelled_at'], 'un-cancelled job stays cancelled'
96 test "update a job without failing script_version check" do
99 id: jobs(:uses_nonexistent_script_version).uuid,
101 owner_uuid: users(:admin).uuid
104 assert_response :success
106 id: jobs(:uses_nonexistent_script_version).uuid,
108 owner_uuid: users(:active).uuid
111 assert_response :success
114 test "search jobs by uuid with >= query" do
115 authorize_with :active
117 filters: [['uuid', '>=', 'zzzzz-8i9sb-pshmckwoma9plh7']]
119 assert_response :success
120 found = assigns(:objects).collect(&:uuid)
121 assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
122 assert_equal false, !!found.index('zzzzz-8i9sb-4cf0nhn6xte809j')
125 test "search jobs by uuid with <= query" do
126 authorize_with :active
128 filters: [['uuid', '<=', 'zzzzz-8i9sb-pshmckwoma9plh7']]
130 assert_response :success
131 found = assigns(:objects).collect(&:uuid)
132 assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
133 assert_equal true, !!found.index('zzzzz-8i9sb-4cf0nhn6xte809j')
136 test "search jobs by uuid with >= and <= query" do
137 authorize_with :active
139 filters: [['uuid', '>=', 'zzzzz-8i9sb-pshmckwoma9plh7'],
140 ['uuid', '<=', 'zzzzz-8i9sb-pshmckwoma9plh7']]
142 assert_response :success
143 found = assigns(:objects).collect(&:uuid)
144 assert_equal found, ['zzzzz-8i9sb-pshmckwoma9plh7']
147 test "search jobs by uuid with < query" do
148 authorize_with :active
150 filters: [['uuid', '<', 'zzzzz-8i9sb-pshmckwoma9plh7']]
152 assert_response :success
153 found = assigns(:objects).collect(&:uuid)
154 assert_equal false, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
155 assert_equal true, !!found.index('zzzzz-8i9sb-4cf0nhn6xte809j')
158 test "search jobs by uuid with like query" do
159 authorize_with :active
161 filters: [['uuid', 'like', '%hmckwoma9pl%']]
163 assert_response :success
164 found = assigns(:objects).collect(&:uuid)
165 assert_equal found, ['zzzzz-8i9sb-pshmckwoma9plh7']
168 test "search jobs by uuid with 'in' query" do
169 authorize_with :active
171 filters: [['uuid', 'in', ['zzzzz-8i9sb-4cf0nhn6xte809j',
172 'zzzzz-8i9sb-pshmckwoma9plh7']]]
174 assert_response :success
175 found = assigns(:objects).collect(&:uuid)
176 assert_equal found.sort, ['zzzzz-8i9sb-4cf0nhn6xte809j',
177 'zzzzz-8i9sb-pshmckwoma9plh7']
180 test "search jobs by started_at with < query" do
181 authorize_with :active
183 filters: [['started_at', '<', Time.now.to_s]]
185 assert_response :success
186 found = assigns(:objects).collect(&:uuid)
187 assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
190 test "search jobs by started_at with > query" do
191 authorize_with :active
193 filters: [['started_at', '>', Time.now.to_s]]
195 assert_response :success
196 assert_equal 0, assigns(:objects).count
199 test "search jobs by started_at with >= query on metric date" do
200 authorize_with :active
202 filters: [['started_at', '>=', '2014-01-01']]
204 assert_response :success
205 found = assigns(:objects).collect(&:uuid)
206 assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
209 test "search jobs by started_at with >= query on metric date and time" do
210 authorize_with :active
212 filters: [['started_at', '>=', '2014-01-01 01:23:45']]
214 assert_response :success
215 found = assigns(:objects).collect(&:uuid)
216 assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
219 test "search jobs with 'any' operator" do
220 authorize_with :active
222 where: { any: ['contains', 'pshmckw'] }
224 assert_response :success
225 found = assigns(:objects).collect(&:uuid)
226 assert_equal 0, found.index('zzzzz-8i9sb-pshmckwoma9plh7')
227 assert_equal 1, found.count
230 test "search jobs by nonexistent column with < query" do
231 authorize_with :active
233 filters: [['is_borked', '<', 'fizzbuzz']]
238 test "finish a job" do
239 authorize_with :active
241 id: jobs(:nearly_finished_job).uuid,
243 output: '551392cc37a317abf865b95f66f4ef94+101',
244 log: '9215de2a951a721f5f156bc08cf63ad7+93',
245 tasks_summary: {done: 1, running: 0, todo: 0, failed: 0},
248 finished_at: Time.now.to_s
251 assert_response :success