Allow users to cancel a running crunch job by updating cancelled_at
[arvados.git] / services / api / test / functional / arvados / v1 / jobs_controller_test.rb
1 require 'test_helper'
2
3 class Arvados::V1::JobsControllerTest < ActionController::TestCase
4
5   test "submit a job" do
6     authorize_with :active
7     post :create, job: {
8       script: "hash",
9       script_version: "master",
10       script_parameters: {}
11     }
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   end
17
18   test "cancel a running job" do
19     # We need to verify that "cancel" creates a trigger file, so first
20     # let's make sure there is no stale trigger file.
21     begin
22       File.unlink(Rails.configuration.crunch_dispatch_hup_trigger)
23     rescue Errno::ENOENT
24     end
25
26     authorize_with :active
27     put :update, {
28       id: jobs(:running).uuid,
29       job: {
30         cancelled_at: 4.day.ago
31       }
32     }
33     assert_response :success
34     assert_not_nil assigns(:object)
35     job = JSON.parse(@response.body)
36     assert_not_nil job['uuid']
37     assert_not_nil job['cancelled_at']
38     assert_not_nil job['cancelled_by_user_uuid']
39     assert_not_nil job['cancelled_by_client_uuid']
40     assert_equal(true, job['cancelled_at'] > 1.minute.ago,
41                  'bogus cancelled_at corrected by server')
42     assert_equal(true,
43                  File.exists?(Rails.configuration.crunch_dispatch_hup_trigger),
44                  'trigger file should be created when job is cancelled')
45
46     put :update, {
47       id: jobs(:running).uuid,
48       job: {
49         cancelled_at: nil
50       }
51     }
52     job = JSON.parse(@response.body)
53     assert_not_nil job['cancelled_at'], 'un-cancelled job stays cancelled'
54   end
55
56 end