3021: Merge branch 'master' into 3021-api-performance
[arvados.git] / services / api / test / integration / jobs_api_test.rb
1 require 'test_helper'
2
3 class JobsApiTest < ActionDispatch::IntegrationTest
4   fixtures :all
5
6   test "cancel job" do
7     post "/arvados/v1/jobs/#{jobs(:running).uuid}/cancel", {:format => :json}, {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:active).api_token}"}
8     assert_response :success
9     assert_equal "arvados#job", json_response['kind']
10     assert_not_nil json_response['cancelled_at']
11   end
12
13   test "cancel someone else's visible job" do
14     post "/arvados/v1/jobs/#{jobs(:runningbarbaz).uuid}/cancel", {:format => :json}, {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:spectator).api_token}"}
15     assert_response 403
16   end
17
18   test "cancel someone else's invisible job" do
19     post "/arvados/v1/jobs/#{jobs(:running).uuid}/cancel", {:format => :json}, {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:spectator).api_token}"}
20     assert_response 404
21   end
22
23   test "task qsequence values automatically increase monotonically" do
24     post_args = ["/arvados/v1/job_tasks",
25                  {job_task: {
26                      job_uuid: jobs(:running).uuid,
27                      sequence: 1,
28                    }},
29                  auth(:active)]
30     last_qsequence = -1
31     (1..3).each do |task_num|
32       @response = nil
33       post(*post_args)
34       assert_response :success
35       qsequence = json_response["qsequence"]
36       assert_not_nil(qsequence, "task not assigned qsequence")
37       assert_operator(qsequence, :>, last_qsequence,
38                       "qsequence did not increase between tasks")
39       last_qsequence = qsequence
40     end
41   end
42 end