3 class Arvados::V1::JobsControllerTest < ActionController::TestCase
9 script_version: "master",
12 assert_response :success
13 assert_not_nil assigns(:object)
14 new_job = JSON.parse(@response.body)
15 assert_not_nil new_job['uuid']
16 assert_not_nil new_job['script_version'].match(/^[0-9a-f]{40}$/)
19 test "normalize output and log uuids when creating job" do
20 authorize_with :active
23 script_version: "master",
24 script_parameters: {},
26 finished_at: Time.now,
29 output: 'd41d8cd98f00b204e9800998ecf8427e+0+K@xyzzy',
30 log: 'd41d8cd98f00b204e9800998ecf8427e+0+K@xyzzy'
32 assert_response :success
33 assert_not_nil assigns(:object)
34 new_job = JSON.parse(@response.body)
35 assert_equal 'd41d8cd98f00b204e9800998ecf8427e+0', new_job['log']
36 assert_equal 'd41d8cd98f00b204e9800998ecf8427e+0', new_job['output']
37 version = new_job['script_version']
39 # Make sure version doesn't get mangled by normalize
40 assert_not_nil version.match(/^[0-9a-f]{40}$/)
47 assert_equal version, JSON.parse(@response.body)['script_version']
50 test "cancel a running job" do
51 # We need to verify that "cancel" creates a trigger file, so first
52 # let's make sure there is no stale trigger file.
54 File.unlink(Rails.configuration.crunch_refresh_trigger)
58 authorize_with :active
60 id: jobs(:running).uuid,
62 cancelled_at: 4.day.ago
65 assert_response :success
66 assert_not_nil assigns(:object)
67 job = JSON.parse(@response.body)
68 assert_not_nil job['uuid']
69 assert_not_nil job['cancelled_at']
70 assert_not_nil job['cancelled_by_user_uuid']
71 assert_not_nil job['cancelled_by_client_uuid']
72 assert_equal(true, Time.parse(job['cancelled_at']) > 1.minute.ago,
73 'server should correct bogus cancelled_at ' +
76 File.exists?(Rails.configuration.crunch_refresh_trigger),
77 'trigger file should be created when job is cancelled')
80 id: jobs(:running).uuid,
85 job = JSON.parse(@response.body)
86 assert_not_nil job['cancelled_at'], 'un-cancelled job stays cancelled'
89 test "update a job without failing script_version check" do
92 id: jobs(:uses_nonexistent_script_version).uuid,
94 owner_uuid: users(:admin).uuid
97 assert_response :success
99 id: jobs(:uses_nonexistent_script_version).uuid,
101 owner_uuid: users(:active).uuid
104 assert_response :success
107 test "search jobs by uuid with >= query" do
108 authorize_with :active
110 filters: [['uuid', '>=', 'zzzzz-8i9sb-pshmckwoma9plh7']]
112 assert_response :success
113 found = assigns(:objects).collect(&:uuid)
114 assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
115 assert_equal false, !!found.index('zzzzz-8i9sb-4cf0nhn6xte809j')
118 test "search jobs by uuid with <= query" do
119 authorize_with :active
121 filters: [['uuid', '<=', 'zzzzz-8i9sb-pshmckwoma9plh7']]
123 assert_response :success
124 found = assigns(:objects).collect(&:uuid)
125 assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
126 assert_equal true, !!found.index('zzzzz-8i9sb-4cf0nhn6xte809j')
129 test "search jobs by uuid with >= and <= query" do
130 authorize_with :active
132 filters: [['uuid', '>=', 'zzzzz-8i9sb-pshmckwoma9plh7'],
133 ['uuid', '<=', 'zzzzz-8i9sb-pshmckwoma9plh7']]
135 assert_response :success
136 found = assigns(:objects).collect(&:uuid)
137 assert_equal found, ['zzzzz-8i9sb-pshmckwoma9plh7']
140 test "search jobs by uuid with < query" do
141 authorize_with :active
143 filters: [['uuid', '<', 'zzzzz-8i9sb-pshmckwoma9plh7']]
145 assert_response :success
146 found = assigns(:objects).collect(&:uuid)
147 assert_equal false, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
148 assert_equal true, !!found.index('zzzzz-8i9sb-4cf0nhn6xte809j')
151 test "search jobs by uuid with like query" do
152 authorize_with :active
154 filters: [['uuid', 'like', '%hmckwoma9pl%']]
156 assert_response :success
157 found = assigns(:objects).collect(&:uuid)
158 assert_equal found, ['zzzzz-8i9sb-pshmckwoma9plh7']
161 test "search jobs by uuid with 'in' query" do
162 authorize_with :active
164 filters: [['uuid', 'in', ['zzzzz-8i9sb-4cf0nhn6xte809j',
165 'zzzzz-8i9sb-pshmckwoma9plh7']]]
167 assert_response :success
168 found = assigns(:objects).collect(&:uuid)
169 assert_equal found.sort, ['zzzzz-8i9sb-4cf0nhn6xte809j',
170 'zzzzz-8i9sb-pshmckwoma9plh7']
173 test "search jobs by started_at with < query" do
174 authorize_with :active
176 filters: [['started_at', '<', Time.now.to_s]]
178 assert_response :success
179 found = assigns(:objects).collect(&:uuid)
180 assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
183 test "search jobs by started_at with > query" do
184 authorize_with :active
186 filters: [['started_at', '>', Time.now.to_s]]
188 assert_response :success
189 assert_equal 0, assigns(:objects).count
192 test "search jobs by started_at with >= query on metric date" do
193 authorize_with :active
195 filters: [['started_at', '>=', '2014-01-01']]
197 assert_response :success
198 found = assigns(:objects).collect(&:uuid)
199 assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
202 test "search jobs by started_at with >= query on metric date and time" do
203 authorize_with :active
205 filters: [['started_at', '>=', '2014-01-01 01:23:45']]
207 assert_response :success
208 found = assigns(:objects).collect(&:uuid)
209 assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
212 test "search jobs with 'any' operator" do
213 authorize_with :active
215 where: { any: ['contains', 'pshmckw'] }
217 assert_response :success
218 found = assigns(:objects).collect(&:uuid)
219 assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
222 test "search jobs by nonexistent column with < query" do
223 authorize_with :active
225 filters: [['is_borked', '<', 'fizzbuzz']]