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}$/)
23 test "normalize output and log uuids when creating job" do
24 authorize_with :active
27 script_version: "master",
28 script_parameters: {},
31 finished_at: Time.now,
34 output: 'd41d8cd98f00b204e9800998ecf8427e+0+K@xyzzy',
35 log: 'd41d8cd98f00b204e9800998ecf8427e+0+K@xyzzy'
37 assert_response :success
38 assert_not_nil assigns(:object)
39 new_job = JSON.parse(@response.body)
40 assert_equal 'd41d8cd98f00b204e9800998ecf8427e+0', new_job['log']
41 assert_equal 'd41d8cd98f00b204e9800998ecf8427e+0', new_job['output']
42 version = new_job['script_version']
44 # Make sure version doesn't get mangled by normalize
45 assert_not_nil version.match(/^[0-9a-f]{40}$/)
52 assert_equal version, JSON.parse(@response.body)['script_version']
55 test "cancel a running job" do
56 # We need to verify that "cancel" creates a trigger file, so first
57 # let's make sure there is no stale trigger file.
59 File.unlink(Rails.configuration.crunch_refresh_trigger)
63 authorize_with :active
65 id: jobs(:running).uuid,
67 cancelled_at: 4.day.ago
70 assert_response :success
71 assert_not_nil assigns(:object)
72 job = JSON.parse(@response.body)
73 assert_not_nil job['uuid']
74 assert_not_nil job['cancelled_at']
75 assert_not_nil job['cancelled_by_user_uuid']
76 assert_not_nil job['cancelled_by_client_uuid']
77 assert_equal(true, Time.parse(job['cancelled_at']) > 1.minute.ago,
78 'server should correct bogus cancelled_at ' +
81 File.exists?(Rails.configuration.crunch_refresh_trigger),
82 'trigger file should be created when job is cancelled')
85 id: jobs(:running).uuid,
90 job = JSON.parse(@response.body)
91 assert_not_nil job['cancelled_at'], 'un-cancelled job stays cancelled'
94 test "update a job without failing script_version check" do
97 id: jobs(:uses_nonexistent_script_version).uuid,
99 owner_uuid: users(:admin).uuid
102 assert_response :success
104 id: jobs(:uses_nonexistent_script_version).uuid,
106 owner_uuid: users(:active).uuid
109 assert_response :success
112 test "search jobs by uuid with >= query" do
113 authorize_with :active
115 filters: [['uuid', '>=', 'zzzzz-8i9sb-pshmckwoma9plh7']]
117 assert_response :success
118 found = assigns(:objects).collect(&:uuid)
119 assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
120 assert_equal false, !!found.index('zzzzz-8i9sb-4cf0nhn6xte809j')
123 test "search jobs by uuid with <= query" do
124 authorize_with :active
126 filters: [['uuid', '<=', 'zzzzz-8i9sb-pshmckwoma9plh7']]
128 assert_response :success
129 found = assigns(:objects).collect(&:uuid)
130 assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
131 assert_equal true, !!found.index('zzzzz-8i9sb-4cf0nhn6xte809j')
134 test "search jobs by uuid with >= and <= query" do
135 authorize_with :active
137 filters: [['uuid', '>=', 'zzzzz-8i9sb-pshmckwoma9plh7'],
138 ['uuid', '<=', 'zzzzz-8i9sb-pshmckwoma9plh7']]
140 assert_response :success
141 found = assigns(:objects).collect(&:uuid)
142 assert_equal found, ['zzzzz-8i9sb-pshmckwoma9plh7']
145 test "search jobs by uuid with < query" do
146 authorize_with :active
148 filters: [['uuid', '<', 'zzzzz-8i9sb-pshmckwoma9plh7']]
150 assert_response :success
151 found = assigns(:objects).collect(&:uuid)
152 assert_equal false, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
153 assert_equal true, !!found.index('zzzzz-8i9sb-4cf0nhn6xte809j')
156 test "search jobs by uuid with like query" do
157 authorize_with :active
159 filters: [['uuid', 'like', '%hmckwoma9pl%']]
161 assert_response :success
162 found = assigns(:objects).collect(&:uuid)
163 assert_equal found, ['zzzzz-8i9sb-pshmckwoma9plh7']
166 test "search jobs by uuid with 'in' query" do
167 authorize_with :active
169 filters: [['uuid', 'in', ['zzzzz-8i9sb-4cf0nhn6xte809j',
170 'zzzzz-8i9sb-pshmckwoma9plh7']]]
172 assert_response :success
173 found = assigns(:objects).collect(&:uuid)
174 assert_equal found.sort, ['zzzzz-8i9sb-4cf0nhn6xte809j',
175 'zzzzz-8i9sb-pshmckwoma9plh7']
178 test "search jobs by started_at with < query" do
179 authorize_with :active
181 filters: [['started_at', '<', Time.now.to_s]]
183 assert_response :success
184 found = assigns(:objects).collect(&:uuid)
185 assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
188 test "search jobs by started_at with > query" do
189 authorize_with :active
191 filters: [['started_at', '>', Time.now.to_s]]
193 assert_response :success
194 assert_equal 0, assigns(:objects).count
197 test "search jobs by started_at with >= query on metric date" do
198 authorize_with :active
200 filters: [['started_at', '>=', '2014-01-01']]
202 assert_response :success
203 found = assigns(:objects).collect(&:uuid)
204 assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
207 test "search jobs by started_at with >= query on metric date and time" do
208 authorize_with :active
210 filters: [['started_at', '>=', '2014-01-01 01:23:45']]
212 assert_response :success
213 found = assigns(:objects).collect(&:uuid)
214 assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
217 test "search jobs with 'any' operator" do
218 authorize_with :active
220 where: { any: ['contains', 'pshmckw'] }
222 assert_response :success
223 found = assigns(:objects).collect(&:uuid)
224 assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7')
227 test "search jobs by nonexistent column with < query" do
228 authorize_with :active
230 filters: [['is_borked', '<', 'fizzbuzz']]