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