X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/9c3904d27dc7d6b6aa5834ff0f5815a8b3685e99..e08c67024acccb83a30d2010c34862973b883585:/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 3b6b786796..0188bd4b13 100644 --- a/services/api/test/functional/arvados/v1/jobs_controller_test.rb +++ b/services/api/test/functional/arvados/v1/jobs_controller_test.rb @@ -3,11 +3,14 @@ load 'test/functional/arvados/v1/git_setup.rb' class Arvados::V1::JobsControllerTest < ActionController::TestCase + include GitSetup + test "submit a job" do authorize_with :active post :create, job: { script: "hash", script_version: "master", + repository: "foo", script_parameters: {} } assert_response :success @@ -15,6 +18,8 @@ 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'] end test "normalize output and log uuids when creating job" do @@ -23,6 +28,7 @@ class Arvados::V1::JobsControllerTest < ActionController::TestCase script: "hash", script_version: "master", script_parameters: {}, + repository: "foo", started_at: Time.now, finished_at: Time.now, running: false, @@ -171,6 +177,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, { @@ -217,7 +257,8 @@ class Arvados::V1::JobsControllerTest < ActionController::TestCase } assert_response :success found = assigns(:objects).collect(&:uuid) - assert_equal true, !!found.index('zzzzz-8i9sb-pshmckwoma9plh7') + assert_equal 0, found.index('zzzzz-8i9sb-pshmckwoma9plh7') + assert_equal 1, found.count end test "search jobs by nonexistent column with < query" do @@ -228,5 +269,35 @@ 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 + + [:active, :admin].each do |which_token| + test "get job queue as #{which_token} user" do + authorize_with which_token + get :queue + assert_response :success + assert_operator 1, :<=, assigns(:objects).count + end + test "get job queue as #{which_token} user, with a filter" do + authorize_with which_token + get :queue, { filters: [['script','=','foo']] } + assert_response :success + assert_equal ['foo'], assigns(:objects).collect(&:script).uniq + end + end end