Fix failing test by parsing timestamp correctly.
[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_refresh_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, Time.parse(job['cancelled_at']) > 1.minute.ago,
41                  'server should correct bogus cancelled_at ' +
42                  job['cancelled_at'])
43     assert_equal(true,
44                  File.exists?(Rails.configuration.crunch_refresh_trigger),
45                  'trigger file should be created when job is cancelled')
46
47     put :update, {
48       id: jobs(:running).uuid,
49       job: {
50         cancelled_at: nil
51       }
52     }
53     job = JSON.parse(@response.body)
54     assert_not_nil job['cancelled_at'], 'un-cancelled job stays cancelled'
55   end
56
57 end