X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/a1c3389d7fe54a7311609e7f74b5a9b3ea825c94..46f3bff06569f06ce84799635ad25727cfd095b5:/apps/workbench/test/unit/work_unit_test.rb diff --git a/apps/workbench/test/unit/work_unit_test.rb b/apps/workbench/test/unit/work_unit_test.rb index 68bc2fdadd..eaf65c578d 100644 --- a/apps/workbench/test/unit/work_unit_test.rb +++ b/apps/workbench/test/unit/work_unit_test.rb @@ -1,6 +1,13 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + require 'test_helper' class WorkUnitTest < ActiveSupport::TestCase + + reset_api_fixtures :after_each_test, false + setup do Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token'] end @@ -10,8 +17,13 @@ class WorkUnitTest < ActiveSupport::TestCase [PipelineInstance, 'pipeline_in_running_state', nil, 1, "Running", nil, 0.0], [PipelineInstance, 'has_component_with_completed_jobs', nil, 3, "Complete", true, 1.0], [PipelineInstance, 'pipeline_with_tagged_collection_input', "pwu", 1, "Ready", nil, 0.0], + [PipelineInstance, 'failed_pipeline_with_two_jobs', nil, 2, "Cancelled", false, 0.0], [Container, 'requester', 'cwu', 1, "Complete", true, 1.0], [ContainerRequest, 'cr_for_requester', 'cwu', 1, "Complete", true, 1.0], + [ContainerRequest, 'queued', 'cwu', 0, "Queued", nil, 0.0], # priority 1 + [ContainerRequest, 'canceled_with_queued_container', 'cwu', 0, "Cancelled", false, 0.0], + [ContainerRequest, 'canceled_with_locked_container', 'cwu', 0, "Cancelled", false, 0.0], + [ContainerRequest, 'canceled_with_running_container', 'cwu', 1, "Running", nil, 0.0], ].each do |type, fixture, label, num_children, state, success, progress| test "children of #{fixture}" do use_token 'active' @@ -20,12 +32,18 @@ class WorkUnitTest < ActiveSupport::TestCase if label != nil assert_equal(label, wu.label) + elsif obj.name.nil? + assert_nil(wu.label) else assert_equal(obj.name, wu.label) end assert_equal(obj['uuid'], wu.uuid) assert_equal(state, wu.state_label) - assert_equal(success, wu.success?) + if success.nil? + assert_nil(wu.success?) + else + assert_equal(success, wu.success?) + end assert_equal(progress, wu.progress) assert_equal(num_children, wu.children.size) @@ -49,11 +67,11 @@ class WorkUnitTest < ActiveSupport::TestCase end [ - [Job, 'running_job_with_components', 1, 1, nil], - [Job, 'queued', nil, nil, 1], - [PipelineInstance, 'pipeline_in_running_state', 1, 1, nil], - [PipelineInstance, 'has_component_with_completed_jobs', 60, 60, nil], - ].each do |type, fixture, walltime, cputime, queuedtime| + [Job, 'running_job_with_components', 1, 1, nil, true], + [Job, 'queued', nil, 0, 1, false], + [PipelineInstance, 'pipeline_in_running_state', 1, 1, nil, false], + [PipelineInstance, 'has_component_with_completed_jobs', 60, 60, nil, true], + ].each do |type, fixture, walltime, cputime, queuedtime, cputime_more_than_walltime| test "times for #{fixture}" do use_token 'active' obj = find_fixture(type, fixture) @@ -62,7 +80,11 @@ class WorkUnitTest < ActiveSupport::TestCase if walltime assert_equal true, (wu.walltime >= walltime) else - assert_equal walltime, wu.walltime + if walltime.nil? + assert_nil wu.walltime + else + assert_equal walltime, wu.walltime + end end if cputime @@ -73,35 +95,13 @@ class WorkUnitTest < ActiveSupport::TestCase if queuedtime assert_equal true, (wu.queuedtime >= queuedtime) + elsif queuedtime.nil? + assert_nil wu.queuedtime else assert_equal queuedtime, wu.queuedtime end - end - end - [ - [Job, 'active', 'running_job_with_components', true], - [Job, 'active', 'queued', false], - [Job, nil, 'completed_job_in_publicly_accessible_project', true], - [Job, 'active', 'completed_job_in_publicly_accessible_project', true], - [PipelineInstance, 'active', 'pipeline_in_running_state', true], # no log, but while running the log link points to pi Log tab - [PipelineInstance, nil, 'pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', false], - [PipelineInstance, 'active', 'pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', false], #no log for completed pi - [Job, nil, 'job_in_publicly_accessible_project_but_other_objects_elsewhere', false, "Log unavailable"], - ].each do |type, token, fixture, has_log, log_link| - test "link_to_log for #{fixture} for #{token}" do - use_token token if token - obj = find_fixture(type, fixture) - wu = obj.work_unit - - link = "#{wu.uri}#Log" if has_log - link_to_log = wu.link_to_log - - if has_log - assert_includes link_to_log, link - else - assert_equal log_link, link_to_log - end + assert_equal cputime_more_than_walltime, (wu.cputime > wu.walltime) if wu.cputime and wu.walltime end end