X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/05d6c99e5b40c7e0792c44a7c2d9af5b91164f9b..586b30b8171da19a4d777c6c2edf4cd7f2fdecfe:/services/api/test/functional/arvados/v1/jobs_controller_test.rb diff --git a/services/api/test/functional/arvados/v1/jobs_controller_test.rb b/services/api/test/functional/arvados/v1/jobs_controller_test.rb index 9904c833c8..03ee3df2e2 100644 --- a/services/api/test/functional/arvados/v1/jobs_controller_test.rb +++ b/services/api/test/functional/arvados/v1/jobs_controller_test.rb @@ -1,9 +1,9 @@ require 'test_helper' -load 'test/functional/arvados/v1/git_setup.rb' +require 'helpers/git_test_helper' class Arvados::V1::JobsControllerTest < ActionController::TestCase - include GitSetup + include GitTestHelper test "submit a job" do authorize_with :active @@ -18,8 +18,7 @@ class Arvados::V1::JobsControllerTest < ActionController::TestCase new_job = JSON.parse(@response.body) assert_not_nil new_job['uuid'] assert_not_nil new_job['script_version'].match(/^[0-9a-f]{40}$/) - # Default: not persistent - assert_equal false, new_job['output_is_persistent'] + assert_equal 0, new_job['priority'] end test "normalize output and log uuids when creating job" do @@ -82,9 +81,19 @@ class Arvados::V1::JobsControllerTest < ActionController::TestCase assert_equal(true, File.exists?(Rails.configuration.crunch_refresh_trigger), 'trigger file should be created when job is cancelled') + end + + test "cancelling a cancelled jobs stays cancelled" do + # We need to verify that "cancel" creates a trigger file, so first + # let's make sure there is no stale trigger file. + begin + File.unlink(Rails.configuration.crunch_refresh_trigger) + rescue Errno::ENOENT + end + authorize_with :active put :update, { - id: jobs(:running).uuid, + id: jobs(:running_cancelled).uuid, job: { cancelled_at: nil } @@ -177,6 +186,40 @@ class Arvados::V1::JobsControllerTest < ActionController::TestCase 'zzzzz-8i9sb-pshmckwoma9plh7'] end + test "search jobs by uuid with 'not in' query" do + exclude_uuids = [jobs(:running).uuid, + jobs(:running_cancelled).uuid] + authorize_with :active + get :index, { + filters: [['uuid', 'not in', exclude_uuids]] + } + assert_response :success + found = assigns(:objects).collect(&:uuid) + assert_not_empty found, "'not in' query returned nothing" + assert_empty(found & exclude_uuids, + "'not in' query returned uuids I asked not to get") + end + + ['=', '!='].each do |operator| + [['uuid', 'zzzzz-8i9sb-pshmckwoma9plh7'], + ['output', nil]].each do |attr, operand| + test "search jobs with #{attr} #{operator} #{operand.inspect} query" do + authorize_with :active + get :index, { + filters: [[attr, operator, operand]] + } + assert_response :success + values = assigns(:objects).collect { |x| x.send(attr) } + assert_not_empty values, "query should return non-empty result" + if operator == '=' + assert_empty values - [operand], "query results do not satisfy query" + else + assert_empty values & [operand], "query results do not satisfy query" + end + end + end + end + test "search jobs by started_at with < query" do authorize_with :active get :index, { @@ -235,5 +278,59 @@ class Arvados::V1::JobsControllerTest < ActionController::TestCase assert_response 422 end + test "finish a job" do + authorize_with :active + put :update, { + id: jobs(:nearly_finished_job).uuid, + job: { + output: '551392cc37a317abf865b95f66f4ef94+101', + log: '9215de2a951a721f5f156bc08cf63ad7+93', + tasks_summary: {done: 1, running: 0, todo: 0, failed: 0}, + success: true, + running: false, + finished_at: Time.now.to_s + } + } + assert_response :success + end + + [:spectator, :admin].each_with_index do |which_token, i| + test "get job queue as #{which_token} user" do + authorize_with which_token + get :queue + assert_response :success + assert_equal i, assigns(:objects).count + end + end + + test "get job queue as with a = filter" do + authorize_with :admin + get :queue, { filters: [['script','=','foo']] } + assert_response :success + assert_equal ['foo'], assigns(:objects).collect(&:script).uniq + assert_equal 0, assigns(:objects)[0].queue_position + end + test "get job queue as with a != filter" do + authorize_with :admin + get :queue, { filters: [['script','!=','foo']] } + assert_response :success + assert_equal 0, assigns(:objects).count + end + + [:spectator, :admin].each do |which_token| + test "get queue_size as #{which_token} user" do + authorize_with which_token + get :queue_size + assert_response :success + assert_equal 1, JSON.parse(@response.body)["queue_size"] + end + end + + test "job includes assigned nodes" do + authorize_with :active + get :show, {id: jobs(:nearly_finished_job).uuid} + assert_response :success + assert_equal([nodes(:busy).uuid], json_response["node_uuids"]) + end end